【问题标题】:Firebase Storage file Type not set when uploading from Firebase Functions (Node)从 Firebase 函数(节点)上传时未设置 Firebase 存储文件类型
【发布时间】:2017-05-06 11:38:48
【问题描述】:

通过 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 存储控制台中查看文件时,文件类型设置为默认应用程序/八位字节流。检查图像的元数据时,它会在“其他元数据”中显示 contentType: 'img/jpeg'。

这里出了什么问题?

【问题讨论】:

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


    【解决方案1】:

    我看到您使用了两次“元数据”。试试这个:

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

    【讨论】:

    • 是的,这就行了,谢谢!我有来自谷歌文档googlecloudplatform.github.io/google-cloud-node/#/docs/storage/…的嵌套方式,但也许那是设置自定义元数据......
    • 显然这种结构效果更好,因为我发现 firebaseStorageDOwnloadTOkens 必须嵌套两次`destination: newFilePathx500, metadata: { metadata:{firebaseStorageDownloadTokens: uuid500}, contentType: 'image/jpeg' }
    猜你喜欢
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 2022-12-15
    • 2021-03-30
    • 1970-01-01
    • 2021-12-02
    • 2021-04-10
    相关资源
    最近更新 更多