从 Firebase 函数(节点)上传时未设置 Firebase 存储文件类型

Firebase Storage file Type not set when uploading from Firebase Functions (Node)

当通过 Firebase Functions (Node) 将转换后的图像 (.jpg) 上传到 google 存储时,我在元数据选项中设置了 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(/(\/)?([^\/]*)$/, `thumb_`);
    // Uploading the thumbnail.

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

当我随后在 Firebase 存储控制台中查看文件时,文件类型设置为默认 application/octet-stream。检查图像的元数据时,它确实显示了 contentType:'img/jpeg' in "Other metaData"。

这里出了什么问题?

我看到您使用了 'metadata' 两次。试试这个:

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