S3.getSignedUrl接受多个内容类型 [英] S3.getSignedUrl to accept multiple content-type

查看:433
本文介绍了S3.getSignedUrl接受多个内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用react-s3-uploader节点程序包,该程序包使用signingUrl来获取用于将对象存储到S3中的signedUrl.

I'm using the react-s3-uploader node package, which takes in a signingUrlfor obtaining a signedUrl for storing an object into S3.

当前,我已经配置了一个lambda函数(带有API Gateway端点)来生成此signedUrl.经过一番修补后,我已经开始使用它了,但是注意到我必须在我的lambda函数中定义content-type,它看起来像这样:

Currently I've configured a lambda function (with an API Gateway endpoint) to generate this signedUrl. After some tinkering, I've got it to work, but noticed that I have to define in my lambda function the content-type, which looks like this:

var AWS = require('aws-sdk');
const S3 = new AWS.S3()
AWS.config.update({
  region: 'us-west-2'
})

exports.handler = function(event, context) {
  console.log('context, ', context)
  console.log('event, ', event)
  var params = {
    Bucket: 'video-bucket',
    Key: 'videoname.mp4',
    Expires: 120,
    ACL: 'public-read',
    ContentType:'video/mp4'
  };
  S3.getSignedUrl('putObject', params, function (err, url) {
    console.log('The URL is', url);
    context.done(null, {signedUrl: url})
  });  
}

问题是我希望此签名的url能够接受多种类型的视频文件,并且我尝试将ContentType设置为video/*,这是行不通的.另外,由于该lambda端点实际上不是上传文件的端点,因此我无法事先将文件类型传递给此函数.

The issue is that I want this signed url to be able to accept multiple types of video files, and I've tried setting ContentType to video/*, which doesn't work. Also, because this lambda endpoint isn't what actually takes the upload, I can't pass in the filetype to this function beforehand.

推荐答案

万一其他人正在寻找有效的答案,我最终发现react-s3-uploader确实将内容类型和文件名传递给了getSignin url(除非我忘记了之前通过API Gateway传递查询),所以我能够在lambda中将其提取为event.params.querystring.contentType.

In case anyone else is looking for a working answer, I eventually found out that react-s3-uploader does pass the content-type and filename over to the getSignin url (except I had forgotten to pass the query through in API Gateway earlier), so I was able to extract it as event.params.querystring.contentType in lambda.

然后在参数中,我简单地设置了{ContentType: event.params.querystring.contentType},现在它可以接受所有文件格式.

Then in the params, I simply set {ContentType: event.params.querystring.contentType} and now it accepts all file formats.

这篇关于S3.getSignedUrl接受多个内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆