2

通過Firebase函數(節點)將轉換後的圖像(.jpg)上傳到谷歌存儲時,我在元數據選項中設置contentType。從Firebase功能(節點)上傳時未設置Firebase存儲文件類型

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'。

screenshot

這是怎麼回事錯在這裏?

回答

1

我看到你正在使用'元數據'兩次。試試這個:

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

是的,伎倆,謝謝!我有谷歌文檔https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/1.1.0/storage/bucket?method=upload的嵌套方式,但也許這是設置自定義元數據然後...... – louisvno

+0

儘管它曾爲UUID – louisvno

+1

顯然,這種結構更好地工作,因爲我發現firebaseStorageDOwnloadTOkens確實有嵌套兩次''目的地:newFilePathx500, 元數據:{ 元數據:{firebaseStorageDownloadTokens:uuid500}, 的contentType :'image/jpeg' }' – louisvno

相關問題