簡體   English   中英

在 Django 只生成 s3 客戶端 generate_presigned_post ,內容類型為 mp4 文件上傳

[英]In Django Generate only s3 client generate_presigned_post with content type for mp4 file upload

上傳視頻( .mp4 )文件后,S3 元數據設置其Content-Type: binary/octet-stream when 使我的瀏覽器強制下載文件而不是播放為了使其在瀏覽器中播放,我需要更改該內容類型以編程方式到django中的“ video/mp4

經過大量時間后,我得出了解決方案:{

def presign_post_S3_url(self, key=None, is_public=False):
    acl = 'private'

    if is_public:
        acl = 'public-read'
    fields = {"acl": acl, "Content-Type": "video/mp4"}
    conditions = [
        {"acl": acl},
        ["starts-with", "$Content-Type", ""]
    ]
    if key is None:
        return ""
   ##s3_client is boto3.client object
    s3_client = self.get_s3_client()
    if s3_client is None:
        return ""
    data = s3_client.generate_presigned_post(
        Bucket=self.bucket,
        Key=key,
        Fields=fields,
        Conditions=conditions

    )
    return data

暫無
暫無

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

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