I'm using an npm package called node-s3-client which is a high-level wrapper for the aws-sdk for Node.js, to upload a local project directory to an S3 bucket.
Using that package, I'm passing some metadata to my files, namely key value pairs for Expires and Cache-Control. I'm uploading an entire directory which consists of HTML, JS, CSS, JPEG files. However when I check my S3 bucket, the headers that I'm setting only applies to JS and CSS files, these headers are not applied to images.
I've gone through the documentation of the package and aws-sdk but I can't seem to find what causes the issue of selectively applying my metadata to some files and not applying to others.
Here's my config object:
const s3 = require('node-s3-client')
const s3Config= {
localDir: './dist',
deleteRemoved: false,
s3Params: {
Bucket: 'cdn',
Prefix: 'dist/',
Metadata: {
'Cache-Control': 'max-age=31536000',
'Expires': oneYearLater(new Date())
}
}
}
const client = s3.createClient({
s3Options: {
accessKeyId: KEY_ID,
secretAccessKey: ACCESS_KEY,
signatureVersion: 'v4',
region: 'us-east-2',
s3DisableBodySigning: true
}
})
client.uploadDir(s3Config)
What might be causing this issue?
I think you have an issue on how you set up the params for your object to upload. Try:
const s3Config= {
localDir: './dist',
deleteRemoved: false,
s3Params: {
Bucket: 'cdn',
Prefix: 'dist/',
CacheControl: 'max-age=31536000',
Expires: oneYearLater(new Date())
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With