pythonamazon-s3boto3

aws s3 uploaded video file cant play, it's download automatically


My video file can uploaded successfully. but i can't play it inside the browser. when i request it automatically downloaded. also i used "content-type: video/mp4" but when i request it's content type is binary/octet-stream

following is my python code.

def get_bucket_sign_url(upload_path):
    try:
        presigned_post = s3_client.generate_presigned_post(
            Bucket=settings.AWS_STORAGE_BUCKET_NAME,
            Key=upload_path",
            Fields={"acl": "public-read", "Content-Type": 'video/mp4'},
            Conditions=[
                {"acl": "public-read"},
                {"Content-Type": 'video/mp4'},
                {"success_action_status": "200"}
            ],
            ExpiresIn=settings.S3_MAX_TIMEOUT # 3600
        )
        return presigned_post
    except Exception:
        return {}

following is my curl code.

curl --location --request POST 'https://******.s3.amazonaws.com/' \
--form 'key=media/customer_videos/5556.mp4' \
--form 'file=@/home/user/Videos/ssm.mp4' \
--form 'acl=public-read' \
--form 'content-type=video/mp4' \
--form 'AWSAccessKeyId=*******' \
--form 'policy=******' \
--form 'signature=******'

Solution

  • Adding the answer for future readers, Content-type is not specified in the correct way. It should be as follows.

    def get_bucket_sign_url(upload_path):
    try:
        presigned_post = s3_client.generate_presigned_post(
            Bucket=settings.AWS_STORAGE_BUCKET_NAME,
            Key=upload_path",
            Fields={"acl": "public-read", "Content-Type": 'video/mp4'},
            Conditions=[
                {"acl": "public-read"},
                {'Metadata': {"Content-Type": 'video/mp4'}},
                {"success_action_status": "200"}
            ],
            ExpiresIn=settings.S3_MAX_TIMEOUT # 3600
        )
        return presigned_post
    except Exception:
        return {}
    

    The Magic line is as follows :

    {'Metadata': {"Content-Type": 'video/mp4'}},