S3上传后无法查看文件

时间:2018-08-19 12:42:06

标签: amazon-web-services amazon-s3

我正在尝试使用AWS S3 Javascript SDK中的S3.upload方法将文件上传到S3。我从输入字段收到了要从客户端上传的文件。我获取该文件并将其传递到我的服务器,然后将其上传到服务器。

Client

file= p._files[0]
fd= new FormData()
fd.append('file', file)
options = {
 filename: file.name,
 content_type: file.type,
 file: fd
}

post(options, route);

Server

 var opts;
      opts = {
        ACL: 'public-read',
        Body: params.file, // formData
        Bucket: this.config.bucket, // this is correct
        ContentType: params.content_type, // application/pdf
        Key: params.filename,
        ServerSideEncryption: 'AES256'
      };
      return this.s3.upload(opts, function(err, data) {
        // send data back to client here
      });

当我查看S3时,实际上无法查看PDF。

Image of erroneous file upload

关于我在做什么错的任何线索吗?我觉得我应该从FormData创建流...当我将其作为文件发送时,它给了我一个无效的有效内容正文请求错误,这就是为什么我切换到FormData的原因。

0 个答案:

没有答案