Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload video to aws S3

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)

like image 742
John Doe Avatar asked Nov 22 '25 09:11

John Doe


1 Answers

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"
  • no space between ':' and video or it will lead to an error as well (at least in my case)
like image 128
John Doe Avatar answered Nov 24 '25 23:11

John Doe