0

我在 S3 存储桶中有文件(PDF 和图像),我正在尝试使用

bucket.getObject(params, function(err, data)

我在 Uint8Array 中获取数据,如何将其作为文件获取?

在该文件的 AWS 属性中:

Content-Disposition : inline
Content-Type : application/pdf

代码:

const params = {
  Bucket: 'mts-test-procedure-document',
  Key: 'Key'

};

bucket.getObject(params, function(err, data){
  if (err) {
    console.log('There was an error getting your file: ', err);
    return false;
  }

  console.log('Successfully got file.', data);
  // return true;
});  

安慰:

Body: Uint8Array(94832) [37, 80, 68, 70, 45, 49, 46, 51, 13, 10, 37, 129, 150, 189, 221, 13, 10, 49, 32, 48, 32, 111, 98, 106, 13, 10, 60, 60, 32, 47, 84, 121, 112, 101, 32, 47, 67, 97, 116, 97, 108, 111, 103, 13, 10, 47, 80, 97, 103, 101, 115, 32, 50, 32, 48, 32, 82, 13, 10, 47, 79, 117, 116, 108, 105, 110, 101, 115, 32, 51, 32, 48, 32, 82, 13, 10, 62, 62, 13, 10, 101, 110, 100, 111, 98, 106, 13, 10, 52, 32, 48, 32, 111, 98, 106, 13, 10, 60, 60, 47, …]
ContentType: "application/pdf"
LastModified: Wed Sep 26 2018 15:34:59 GMT-0400 (Eastern Daylight Time) {}
Metadata: {}
4

1 回答 1

0

您需要在上传文件时进行定义。对于图像

    Content-Type: "image/jpeg"

对于 jpeg 图片

对于pdf:

 Content-Type: "application/pdf"
 Content-Disposition: inline;

更多内容类型可以在https://s3browser.com/features-content-mime-types-editor.aspx找到

于 2018-09-26T17:18:50.007 回答