aws s3上传的视频文件无法播放,自动下载

问题描述 投票:0回答:2

我的视频文件可以上传成功。但我无法在浏览器中播放它。 当我请求时它会自动下载。 我还使用了“内容类型:视频/mp4”,但是当我请求它的内容类型是二进制/八位字节流

以下是我的Python代码。

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

以下是我的curl代码。

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=******'
python amazon-s3 boto3
2个回答
3
投票

检查上传的S3中的

metadata
。值字段应为
video/mp4
。请参考以下截图

enter image description here


2
投票

为未来的读者添加答案, 未以正确的方式指定内容类型。 应该是这样的。

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

魔线如下:

{'Metadata': {"Content-Type": 'video/mp4'}},
© www.soinside.com 2019 - 2024. All rights reserved.