簡體   English   中英

如何使用 API GW 和 python 將視頻上傳到 s3?

[英]How to upload video to s3 using API GW and python?

我正在嘗試制作一個 api ,它將視頻上傳到 s3。 我已經准備好設法在 s3 中上傳視頻,但問題是視頻文件無法正常工作。 我檢查了視頻文件的內容類型,它是二進制/八位字節流,而不是視頻/mp4。 所以我在調用 put_object api 時將內容類型設置為“video/mp4”,但它仍然無法正常工作。

我使用 Lambda function 將視頻放入 s3。 這是我的 lambda 代碼 -

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,
    }

知道如何解決這個問題嗎?

基於使用 AWS API 網關和 AWS Lambda 將二進制文件上傳到 S3 中的示例 | 通過奧馬爾哈內茨 | 創業 | ,看來您需要從 base64 解碼文件:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM