简体   繁体   中英

How to upload video to s3 using API GW and python?

Im trying to make a api which will upload video to s3. I all ready managed to upload the video in s3, but the problem is the video file is not working. i checked content-type of video file, and it's binary/octet-stream instead on video/mp4. So i set content-type to "video/mp4" while calling put_object api, but it still not working.

I use Lambda function for putting the video to s3. here is my lambda code -

import json
import base64
import boto3



def lambda_handler(event, context):
    

    bucket_name = 'ad-live-streaming'
    s3_client = boto3.client('s3')
    
    file_content = event['content']
    merchantId = event['merchantId']
    catelogId = event['catelogId']
    file_name = event['fileName']
    
    file_path = '{}/{}/{}.mp4'.format(merchantId, catelogId, file_name)
 

    s3_response = s3_client.put_object(Bucket=bucket_name, Key=file_path, Body=file_content, ContentType='video/mp4')    

        
    return {
        'statusCode': 200,
        "merchantId":merchantId,
        "catelogId":catelogId,
        "file_name":file_name,
    }

Any idea how to solve this issue?

Based on the example in Upload binary files to S3 using AWS API Gateway with AWS Lambda | by Omer Hanetz | The Startup | Medium , it appears that you need to decode the file from base64:

file_content = base64.b64decode(event['content'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM