javascript - (nodeJS) S3 对象的内容类型 : manually set to 'image/jpeg' but in S3 console comes up as 'application/octet'

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

我有一个 JPEG 缓冲区,它可以从 S3 成功上传和下载。但是,我试图通过 Messenger API 发送它,当以编程方式访问它时,Messenger 会抛出错误,因为根据 S3 控制台,图像的实际 Content-Typeapplication/八位字节流

我手动输入的元数据显示在 x-amz-meta-content-type 下。根据 AWS 文档,这是默认行为。我如何覆盖它以在 Content-Type 下获取 image/jpeg

我的代码:

var s3 = new AWS.S3();
var params = {
  Body: buffer,
  Bucket: <bucket>,
  Key: <key>,
  Metadata: {
    'Content-Type': 'image/jpeg'
  }
};
s3.putObject(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else  {
    console.log(data);
  }
})

最佳答案

不要在 Metadata 部分设置它,这仅适用于将以 x-amz-meta 为前缀的属性。在主级别有一个 ContentType 参数,如下所示:

var s3 = new AWS.S3();
var params = {
  Body: buffer,
  Bucket: <bucket>,
  Key: <key>,
  ContentType: 'image/jpeg'
};
s3.putObject(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else  {
    console.log(data);
  }
})

关于javascript - (nodeJS) S3 对象的内容类型 : manually set to 'image/jpeg' but in S3 console comes up as 'application/octet' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47096483/

相关文章:

Javascript 排序 html 元素

node.js - 如何在数组中查找数组的大小?

node.js - Nodejs : peerDependencies error while installing depedencNodejs

amazon-web-services - AWS 批处理数组 - 数组大小?

amazon-web-services - AWS 上的 Mesosphere DCOS 集群。 EC2 实例终止并在停止后再次重新启动

javascript - 需要 Javascript 或 JQuery 中的花式循环

javascript - 调整浏览器大小后如何获取 Canvas 的宽度和高度

javascript - 将鼠标悬停在子分区上时更改主分区的背景

Node.js:作为文件或交互式运行脚本会产生不同的结果

javascript - 来自 Lambda 的 AWS Cognito adminCreateUser,使用 Amplify CLI 创建