我正在尝试使用API接口将视频上传到S3存储桶,我遵循了预签名URL过程,这是我的lambda函数,它返回预签名URL(貌似正确地返回了预签名URL):
import json
import base64
import boto3
import uuid
BUCKET_NAME = 'redacted-bucket-instance'
def lambda_handler(event, context):
actionId = uuid.uuid4()
file_path = "video_uploads/" + str(actionId) + ".mp4"
s3 = boto3.client('s3')
s3Params = {
"Bucket": BUCKET_NAME,
"Key": file_path,
"ContentType": 'video/mp4',
"ACL": 'public-read'
}
try:
s3_response = s3.generate_presigned_url('put_object', Params=s3Params, ExpiresIn=3600, HttpMethod="PUT")
except Exception as e:
raise IOError(e)
return {
'statusCode': 200,
'body': {
'file_path': file_path,
'url': s3_response
}
}
当我尝试上传像这样的带有卷曲的mp4视频时,例如: curl -X PUT -F'data=@ch01_00000100055009702.mp4'https://redacted-bucket-instance.s3.amazonaws.com//video_uploads/a845a97f-a218-4815-a836-376e498a4334.mp4?AWSAccessKeyId=ASIAWZPXMJR5V7GEHUJJ&Signature=zDsdfsdfqsdfD&content-type=video%2Fmp4&x-amz-acl=public-read&etc
或
curl -X PUT --data-binary'@ ch01_00000100055009702.mp4'https://redacted-bucket-instance.s3.amazonaws.com//video_uploads/a845a97f-a218-4815-a836-376e498a4334.mp4?AWSAccessKeyId=ASIAWZPXMJR5V7GEHUJJ&Signature=zDsdfsdfqsdfD&content-type=video%2Fmp4&x-amz-acl=public-read&etc
在两种情况下,终端都关闭...在这里我怎么可能做错了?
(两个URL当然都不是,只是为了演示而已)
编辑
为网址添加引号可防止终端关闭并给出响应。(我想有些字符需要转义)
现在我收到此错误:
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>ASIAWZPXMJR54PMEJVPQ</AWSAccessKeyId>
我应该在请求中添加标题以使其正常工作吗?
(我更新了预签名的网址,以确保在设置过程中有效)
答案 0 :(得分:0)
对我来说,解决方案是先为网址添加引号(如编辑中所述),然后添加Content-Type标头
-H "Content-Type:video/mp4"