Amazon S3中的节点file upload错误

在亚马逊S3上传文件时出现错误。 代码如下:

const s3 = require('s3'); const client = s3.createClient({ maxAsyncS3: 100, s3RetryCount: 3, s3RetryDelay: 30000, multipartUploadThreshold: 20971520, multipartUploadSize: 15728640, s3Options: { accessKeyId: "xxxx", secretAccessKey: "yyyy", region: "us-east-2", }, }); const params = { localDir: "file-path", s3Params: { Bucket: "bucket-name", Prefix: "images/image.jpg" }, }; const uploader = client.uploadDir(params); uploader.on('error', (err) => { console.error("unable to upload:", err.stack); }); uploader.on('progress', () => { console.log("progress", uploader.progressMd5Amount, uploader.progressAmount, uploader.progressTotal); }); uploader.on('end', () => { console.log("done uploading"); }); 

我得到的错误是:

无法上传:错误:AWS.S3中的SigV4不支持非文件stream对象

你应该通过上传方法一个文件。 这里是一个例子:

  var file = files[0]; var fileName = file.name; var albumPhotosKey = encodeURIComponent(albumName) + '//'; var photoKey = albumPhotosKey + fileName; s3.upload({ Key: photoKey, Body: file, ACL: 'public-read' }, function(err, data) { if (err) { return alert('There was an error uploading your photo: ', err.message); } alert('Successfully uploaded photo.'); viewAlbum(albumName); }); } 

更多示例: http : //docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album-full.html