When uploading a converted image (.jpg) to the google storage through Firebase Functions (Node) I set the contentType in the metadata options.
return bucket.file(filePath).download({destination: tempFilePath})
.then(() => {
console.log('Image downloaded locally to', tempFilePath);
// Generate a thumbnail using ImageMagick.
return spawn('convert', [tempFilePath, '-thumbnail', '200x200>', tempFilePath])
})
.then(() => {
console.log('Thumbnail created at', tempFilePath);
// Add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
// Uploading the thumbnail.
return bucket.upload(tempFilePath, { destination: thumbFilePath,
metadata: {
metadata: {
contentType: 'image/jpeg',
firebaseStorageDownloadTokens: uuid
}
}
});
When i then view the file in Firebase storage console, the file Type is however set to the default application/octet-stream. When checking the metadata of the image it does say contentType: 'img/jpeg' in "Other metaData".
What is going wrong here?
I see you are using 'metadata' twice. Try this instead:
return bucket.upload(tempFilePath, {
destination: thumbFilePath,
metadata: {
contentType: 'image/jpeg',
firebaseStorageDownloadTokens: uuid
}
});
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