从Firebasefunction(节点)上传时,Firebase存储文件types未设置

通过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 } } }); 

当我在Firebase存储控制台中查看文件时,文件types将被设置为默认应用程序/八位字节stream。 当检查图像的元数据时,它会在“其他元数据”中显示contentType:'img / jpeg'。

截图

这里怎么了?

我看到你正在使用'元数据'两次。 试试这个:

 return bucket.upload(tempFilePath, { destination: thumbFilePath, metadata: { contentType: 'image/jpeg', firebaseStorageDownloadTokens: uuid } });