- Newest
- Most votes
- Most comments
Hello Anand,
Yes, you can use AWS SDK to generate a pre-signed URL to upload an object to a specified S3 bucket with metadata. What I'm not sure, and I haven't been able to test, is that you can set tags directly; but something I've used in the past is custom object metadata. I suggest you try first with the "x-amz-tagging" and if it doesn't let you set it, try with user-defined object metadata "x-amz-meta-yourcustomkey: yourcustomvalue". Please check the following documentation as a reference:
- Boto3 S3 Presigned URLs - Generating a pre-signed URL to upload a file
- generate_presigned_post function
- Working with object metadata
Please let me know if that works for your use-case; I'm eager to learn the solution you finally apply, even though, unfortunately, I don't have the time right now to help you troubleshoot as this is not the official AWS support and just a community resource.
If the answer is helpful, please click "Accept Answer" and upvote it.
I found a solution that worked for me.
const s3Client = new S3Client({ region: AWS_REGION });
const putObjectCommand = new PutObjectCommand({ Bucket: bucket, Key: s3_key, Tagging: 'tag=myTag'});
const unhoistableHeaders : Set<string> = new Set(['x-amz-tagging']);
return await getSignedUrl(s3Client, putObjectCommand,{ unhoistableHeaders: unhoistableHeaders });
It appears that you need to add the x-amz-tagging header to the list of unhoistable headers (https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/requestpresigningarguments.html).
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated a year ago
I tried with x-amz-tagging but ran into this error " The request signature we calculated does not match the signature you provided. Check your key and signing method." I tried with new keys too but no luck
You might need to generate the pre-signed URL in the correct region (you should call the endpoint in the same region where your bucket lives) or have some unsupported characters in the key name. Can you try that and see if that fixes the issue?
Some more details. Here is what I tried:
Result:
h ttps://telemetry-upload.s3.us-east-2.amazonaws.com/filename?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAXGUCOVV4FKISXDJR%2F20231027%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20231027T164533Z&X-Amz-Expires=900&X-Amz-Signature=699be84c8ccb32d35c7446a6b3f188cb4a63e60dd707f463bbedfc025c2afe2f&X-Amz-SignedHeaders=host&x-amz-tagging=tag%3DmyTag&x-id=PutObject
Verified that the header on the http request: X-Amz-Tagging: tag=mytag is there.
Result is the server does not return a response, connection is terminated. But when I remove the 'x-amz-tagging': 'tag=mytag' from my request the file is uploaded with a 200 response. No tag exists on the newly uploaded file.