在 Django 中仅生成内容类型为 mp4 文件上传的 s3 客户端 generate_presigned_post
In Django Generate only s3 client generate_presigned_post with content type for mp4 file upload
上传视频(.mp4)文件后,S3 元数据设置其 Content-Type:binary/octet-stream
什么时候让我的浏览器强制下载文件而不是播放为了让它在浏览器中播放我需要在 django
我花了很多时间来解决这个问题:
{
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
上传视频(.mp4)文件后,S3 元数据设置其 Content-Type:binary/octet-stream 什么时候让我的浏览器强制下载文件而不是播放为了让它在浏览器中播放我需要在 django
我花了很多时间来解决这个问题: {
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