Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 当我在标题中使用x-amz标记时,它给出了403禁止的错误_Amazon Web Services_Amazon S3_Http Headers_Vercel_Pre Signed Url - Fatal编程技术网

Amazon web services 当我在标题中使用x-amz标记时,它给出了403禁止的错误

Amazon web services 当我在标题中使用x-amz标记时,它给出了403禁止的错误,amazon-web-services,amazon-s3,http-headers,vercel,pre-signed-url,Amazon Web Services,Amazon S3,Http Headers,Vercel,Pre Signed Url,您好,我有一个正在工作的无服务器函数,它使用s3 signedurl将文件放入s3存储桶中,使用的是无服务器框架,我正在尝试使用Next将其迁移到vercel无服务器函数 该函数通过serverless函数和Postman工作,但当我尝试使用Vercel时,尽管它生成signedurl ok,但当我尝试将其与“x-amz-tagging”=“test”头一起使用时,我得到一个403错误。以下是我代码的相关部分: //serverless function const allowCors = fn

您好,我有一个正在工作的无服务器函数,它使用s3 signedurl将文件放入s3存储桶中,使用的是无服务器框架,我正在尝试使用Next将其迁移到vercel无服务器函数

该函数通过serverless函数和Postman工作,但当我尝试使用Vercel时,尽管它生成signedurl ok,但当我尝试将其与
“x-amz-tagging”=“test”
头一起使用时,我得到一个403错误。以下是我代码的相关部分:

//serverless function
const allowCors = fn => async (req, res) => {
        res.setHeader('Access-Control-Allow-Credentials', true)
        res.setHeader('Access-Control-Allow-Origin', '*')
        res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT')
        res.setHeader(
           'Access-Control-Allow-Headers',
           'X-CSRF-Token, X-Requested-With, x-amz-tagging, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
        )
        return await fn(req, res)
}

function requestUploadURL(req, res) {
...
}
module.exports = allowCors(requestUploadURL)

感激地收到的任何建议

出于某种原因,我还需要使用
标记:'
作为被
allowCors
函数包装的函数中s3参数的一部分。我以前不需要这样做

const { body } = req
        const s3Params = {
                Bucket: UNIQUEBUCKET,
                Key: body.name,
                ContentType: body.type,
                ACL: 'public-read',
                Tagging: '',
        }

        const uploadURL = s3.getSignedUrl('putObject', s3Params)


标记的形式应该是
name=value&name2=value2&…
,而不仅仅是
name
。您预先签署的url允许指定标签吗?谢谢@luk2302。这种标记在无服务器框架上可以正常工作,尽管它可能不是标准的,我相信它允许标记,就像在无服务器版本上一样,尽管我不确定是否正确配置了“访问控制允许标头”。以前我不必使用这个。我只使用了“Access Control Allow Credentials”:true和“Access Control Allow Origin”:“*”我已经完全删除了“Access Control Allow Headers”,它仍然给出了一个403,带有“x-amz-tagging”:“test”和“x-amz-tagging”:“name=test”
const { body } = req
        const s3Params = {
                Bucket: UNIQUEBUCKET,
                Key: body.name,
                ContentType: body.type,
                ACL: 'public-read',
                Tagging: '',
        }

        const uploadURL = s3.getSignedUrl('putObject', s3Params)