Closed ZenWayne closed 1 month ago
checking the cors setting and use middlewarestack.add this problem has been solved. add x-amz-meta-cid on cors setting
{
"CORSRules": [
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
""
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2",
"x-amz-meta-cid"
],
"MaxAgeSeconds": 3000
}
]
}
fetch CID on javascript from aws v3 sdk example
const command = new PutObjectCommand({...});
command.middlewareStack.add(
(next) => async (args) => {
// Check if request is incoming as middleware works both ways
const response = await next(args);
if (!response.response.statusCode) return response;
// Get cid from headers
const cid = response.response.headers["x-amz-meta-cid"];
console.log(cid);
return response;
},
{
step: "build",
name: "addCidToOutput",
},
);
const res = await client.send(command);
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Describe the feature
I want to retrieve some value located on response header of PutObjectCommand, however I can not find a way to do that, here are my code snippet
Use Case
I use aws-sdk for filebase ipfs platform, when I use PutObjectCommand I wanna get CID of the file I uploaded. and the CID is located on http response header, whose name is 'X-Amz-Meta-Cid'
Proposed Solution
I preferred add a variable referred to the response header in the return value of S3.send() function
Other Information
No response
Acknowledgements
SDK version used
@aws-sdk/client-s3 v3.574.0
Environment details (OS name and version, etc.)
Windows 11