Aws-sdk s3 upload CORS error cause by CacheControl Option #4091
JANDA-Developers
started this conversation in
General
Replies: 1 comment
-
I have exact same issue. aws-sdk version is 2.1217.0. import S3 from 'aws-sdk/clients/s3';
import fetch from 'node-fetch';
const s3 = new S3({
endpoint: process.env.S3_ENDPOINT,
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
signatureVersion: 'v4',
});
async function main() {
await s3.putBucketCors({
Bucket: process.env.S3_BUCKET_NAME,
CORSConfiguration: {
CORSRules: [
{
AllowedHeaders: ['*'],
AllowedMethods: ['GET'],
AllowedOrigins: ['*'],
ExposeHeaders: ['ETag'],
}
]
}
}).promise();
const result = await fetch(process.env.MYAPI_ENDPOINT);
if (result.status === 200) {
await s3.putObject({
Bucket: process.env.S3_BUCKET_NAME,
Key: 'data.json',
ContentType: 'application/json',
CacheControl: 'max-age=0,must-revalidate,public', // THIS CAUSE CORS ERROR ON BROWSER CLIENT!!
Body: text,
}).promise();
}
}
main(); Workaround for browser side. await fetch(S3URL, { cache: 'no-cache' }); // SPECIFY cache OPTION TO 'no-cache' SO THAT ALWAYS REVALIDATE |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Confirm by changing [ ] to [x] below:
version
"aws-sdk": "^2.586.0",
Describe the question
My code is looks like this and when
If I upload this with the CacheControl option, upload works fine.
But when I load it on the client side I get a CORS error.
If I remove CachControl, obviously the CORS error doesn't come up.
My Bucket has CORS-Policy like this
Headers with CacheControl Param
Headers without CachControl Param
With CacheControl param,
My Allow headers are gone. Why is that?
Beta Was this translation helpful? Give feedback.
All reactions