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
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!