通过 Firebase 函数(节点)将转换后的图像 (.jpg) 上传到谷歌存储时,我在元数据选项中设置了 contentType。
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
}
}
});
Run Code Online (Sandbox Code Playgroud)
当我然后在 Firebase 存储控制台中查看文件时,文件类型被设置为默认的应用程序/八位字节流。检查图像的元数据时,它确实在“其他元数据”中说 …