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
Node.js 上载时aws预签名url请求签名不匹配_Node.js_Amazon S3_Pre Signed Url - Fatal编程技术网

Node.js 上载时aws预签名url请求签名不匹配

Node.js 上载时aws预签名url请求签名不匹配,node.js,amazon-s3,pre-signed-url,Node.js,Amazon S3,Pre Signed Url,我正在尝试使用预先签名的url上载图像 const s3Params = { Bucket: config.MAIN_BUCKET, Key: S3_BUCKET + '/'+fileName, ContentType: fileType, Expires: 900, ACL: 'public-read' }; const s3 = new AWS.S3({ accessKeyId: config.accessKeyId, secretAccessKey: confi

我正在尝试使用预先签名的url上载图像

const s3Params = {
  Bucket: config.MAIN_BUCKET,
  Key: S3_BUCKET + '/'+fileName,
  ContentType: fileType,
  Expires: 900,
  ACL: 'public-read'
};
const s3 = new AWS.S3({
  accessKeyId: config.accessKeyId,
  secretAccessKey: config.secretAccessKey,
  'region': config.region
});
const url = await s3.getSignedUrlPromise('putObject', s3Params)
return url
我得到了一个类似的url

  • 我曾尝试上载内容类型为image/jpg、多部分/表单数据的文件
  • 尝试在没有文件类型和上载的情况下生成url
  • 试推贴法
  • 但似乎什么都不管用

    错误总是:

    我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法

    Access凭据具有适当的权限,因为在尝试通过对象上载(通过api而不是预先签名的url)时,这些上载文件可以正常运行

    编辑:


    邮递员似乎正在以多部分/表单数据的形式发送内容类型;边界=------------------------------------336459561795502380899802。这里添加了额外的边界。如何解决这个问题?

    我正在测试postman上的表单数据。但是getsignedUrl()函数不支持这一点。尝试使用二进制,效果很好。对于multipart,aws sdk中似乎有一个不同的函数,根据aws S3文档,S3默认使用SignatureVersion4

    但是nodejs AWS-SDK默认使用SignatureVersion2

    因此,您必须在请求头中显式指定SignatureVersion4

    在S3配置中添加此代码

    s3=新的AWS.s3({
    “签名转换”:“v4”
    
    });
    请在生成url时发布上载imagetry
    ContentType:“应用程序/八位字节流”
    的客户端代码,并在上载时传递相同的
    内容类型。