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

时间:2017-05-06 11:38:49

标签: node.js firebase firebase-storage google-cloud-functions

通过Firebase功能(节点)将转换后的图像(.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(/(\/)?([^\/]*)$/, `$1thumb_$2`);
    // Uploading the thumbnail.

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

然后,当我在Firebase存储控制台中查看文件时,文件Type将设置为默认的application / octet-stream。在检查图像的元数据时,它会说contentType:' img / jpeg'在"其他元数据"。

screenshot

这里出了什么问题?

1 个答案:

答案 0 :(得分:2)

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

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