【问题标题】:amazon s3 InvalidRequest error in node.jsnode.js中的亚马逊s3 InvalidRequest错误
【发布时间】:2018-05-18 20:58:28
【问题描述】:
var s3 = require('s3');
var client = s3.createClient({
maxAsyncS3: 20,    
s3RetryCount: 3,   
s3RetryDelay: 1000, 
multipartUploadThreshold: 20971520, 
multipartUploadSize: 15728640,
s3Options: {
 accessKeyId: "ABC",
  secretAccessKey: "XYZ",
  region: " us-east-2",
  endpoint: 's3-us-east-2.amazonaws.com',
  ACL: ''
  }
 });
  var uploadParams = {
    localFile: '/home/onur/Desktop/cwiz.jpg',
    s3Params: {
        Bucket: 'cwizz',
        Key: '', // How can I found bucked key ?

    }
};

var uploader = client.uploadFile(uploadParams);

uploader.on('error', function(err) {
  return console.error('unable to upload:', err, err.stack);
});
uploader.on('end', function() {
  console.log("done uploading");
});

我怎样才能找到bucket key?

无法上传:{ InvalidRequest:不支持您提供的授权机制。请使用 AWS4-HMAC-SHA256。

【问题讨论】:

  • 引号里面有一个杂散的空格,这里:region: " us-east-2",

标签: node.js amazon-web-services amazon-s3


【解决方案1】:

存储桶键是您希望上传文件的存储桶内的路径。例如以下会将您的图像上传到 cwizz 存储桶内的 images/cwiz.jpg。此外,您不需要 s3Options 对象中的区域、端点和 ACL。

var s3 = require('s3');
var client = s3.createClient({
maxAsyncS3: 20,    
s3RetryCount: 3,   
s3RetryDelay: 1000, 
multipartUploadThreshold: 20971520, 
multipartUploadSize: 15728640,
s3Options: {
 accessKeyId: "ABC",
  secretAccessKey: "XYZ"
  }
 });
  var uploadParams = {
    localFile: '/home/onur/Desktop/cwiz.jpg',
    s3Params: {
        Bucket: 'cwizz',
        Key: 'images/cwiz.jpg',

    }
};

var uploader = client.uploadFile(uploadParams);

uploader.on('error', function(err) {
  return console.error('unable to upload:', err, err.stack);
});
uploader.on('end', function() {
  console.log("done uploading");
});

【讨论】:

    猜你喜欢
    • 2016-12-22
    • 2012-09-28
    • 2010-10-20
    • 2012-05-01
    • 2018-02-10
    • 2013-05-12
    • 2017-07-18
    • 1970-01-01
    相关资源
    最近更新 更多