- 최신
- 최다 투표
- 가장 많은 댓글
【以下的回答经过翻译处理】 根据 CLI 的文档,生成的预签名 URL 仅可用于“GET”。
当我需要 POST
时,我保存了这个URL;如果您需要 PUT
,您应该能够修改它以使用 generate_presigned_url()
而不是 generate_presigned_post()
。请注意,这将 boto3 库与 Python 结合使用,因此您需要安排让您的 Python 安装可以访问该库(例如,pip install boto3
)。输出包括为 curl 和 httpie 格式化的值,我希望它们有用。
获取预签名 POST URL 的 Python 脚本:
import boto3 client = boto3.client("s3")
get presigned info
note other params can be passed here, including expiration
see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.generate_presigned_post
info = client.generate_presigned_post(Bucket="some-bucket", Key="filename.txt")
print the "fields" out in the right format to feed to httpie
print(" ".join(f"{k}='{v}'" for (k, v) in info["fields"].items()))
for curl, use this
print(" ".join(f"-F {k}='{v}'" for (k, v) in info["fields"].items()))
confirm the URL
print(info["url"])
下面是使用返回值的示例。您可能需要删除注释行才能让您的 shell 有效。
与 httpie 一起使用:
http --form -v \
this the the URL from Python output
https://some-bucket.s3.amazonaws.com/ \
these are the copy/pasted fields from Python output
key='filename.txt' AWSAccessKeyId='AKIA...EWS3' policy='eyJl...dfQ==' signature='RcU...XLw=' \
this is the file to upload
与curl一起使用:
curl -X POST \
the copy/pasted fields
-F key='filename.txt' -F AWSAccessKeyId='AKIA...EWS3' -F policy='eyJle...dfQ==' -F signature='RcU9...XLw=' \
the file to upload
-F file=@local-filename.txt \
the URL
https://some-bucket.s3.amazonaws.com/
관련 콘텐츠
- AWS 공식업데이트됨 일 년 전
- AWS 공식업데이트됨 2년 전
- AWS 공식업데이트됨 일 년 전