I am trying to upload a video to an S3 bucket using the API interface, I followed the presigned URL procedure, here is my lambda function that returns the presigned URL (it returns the presigned url correctly - seemingly):
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
}
}
when I try to upload an mp4 video with curl like this for ex: 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
or
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
in both cases, the terminal closes...whatcould I be doing wrong here?
(both url are not the ones received of course but just there for demonstration)
Edit
Adding quotes for the url prevented the terminal from closing and gave a reponse.(I'm guessing some characters needed to be escaped)
Now I'm getting this error:
<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>
Should I add headers in the request for it to work?
(I renewed the presigned url to make sure it's valid during teseting)
The solution for me was to first add quotes for the url (as mentioned in the edit) and also add a Content-Type header
-H "Content-Type:video/mp4"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With