node.js中的Amazon S3 InvalidRequest错误


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");
});

我如何找到钥匙?

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

存储键键是您希望上传文件的存储桶内的路径。例如以下将使您的图像上传到cwizz桶内的图像/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");
});

最新更新