我的视频文件可以上传成功。但我无法在浏览器中播放它。 当我请求时它会自动下载。 我还使用了“内容类型:视频/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=******'
为未来的读者添加答案, 未以正确的方式指定内容类型。 应该是这样的。
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'}},