英文:
Using presigned to upload a file to "Glacier Instant Retrieval" with tags
问题
I'm using the following code:
import boto3
import requests
s3_client = boto3.client(
"s3",
region_name=AWS_REGION,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)
url = s3_client.generate_presigned_url(
"put_object",
Params=dict(
Bucket=MY_BUCKET,
Key=key,
StorageClass="GLACIER_IR",
Tagging="key1=value1&key2=value2"
),
ExpiresIn=EXPIRATION,
)
with open(file_path, "rb") as file:
data = file.read()
response = requests.put(url, data=data)
The response is 200, the file is uploaded, but the tags are missing. I tried to do the same with the regular boto3 function (see code below) and it did work, so why the presigned URL does not?
s3_client.put_object(Bucket=MY_BUCKET, Key=key, Body=file, StorageClass="GLACIER_IR",
Tagging="key1=value1&key2=value2")
I also tried to change the storage class and got the same problem.
英文:
I'm using the following code:
import boto3
import requests
s3_client = boto3.client(
"s3",
region_name=AWS_REGION,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)
url = s3_client.generate_presigned_url(
"put_object",
Params=dict(
Bucket=MY_BUCKET,
Key=key,
StorageClass="GLACIER_IR",
Tagging="key1=value1&key2=value2"
),
ExpiresIn=EXPIRATION,
)
with open(file_path, "rb") as file:
data = file.read()
response = requests.put(url, data=data)
The response is 200, the file is uploaded, but the tags are missing. I tried to do the same with the regular boto3 function (see code below) and it did work, so why the presigned url does not?
s3_client.put_object(Bucket=MY_BUCKET, Key=key, Body=file, StorageClass="GLACIER_IR",
Tagging="key1=value1&key2=value2")
I also tried to change the storage class and got the same problem
答案1
得分: 0
"As luk3202 said, the tags are specified during the upload, so I tried:
response = requests.put(url, data=data,
headers={"x-amz-tagging": "key1=value1&key2=value2"})
and it worked!"
英文:
As luk3202 said, the tags are specified during the upload, so I tried:
response = requests.put(url, data=data,
headers={"x-amz-tagging": "key1=value1&key2=value2"})
and it worked!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论