Upload Image into S3 bucket using Api Gateway, Lambda funnction

旧城冷巷雨未停 提交于 2019-12-01 11:08:23

When uploading objects to S3 that should be opened in a web browser, you need to set the correct content type. When S3 serves your object, the content type you set will be sent as a HTTP header.

Web browsers use MIME types to determine how to process URLs, not file extensions.

In your case, the content type is missing from the parameters your are passing to s3.upload. Moreover, the key is incorrect.

It should be:

const params = {
  Bucket: 'bucket-name',
  Key: fileFullName // must be a path within your bucket and not an url like you have in fileFullPath,
  Body: buffer,
  ContentType: fileMime.mime // Sets the content type header, without this your browser cannot infer the type (browsers use mime types, not file extensions)
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!