Saturday 6 May 2017

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

When uploading a converted image (.jpg) to the google storage through Firebase Functions (Node) I set the contentType in the metadata options.

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

When i then view the file in Firebase storage console, the file Type is however set to the default application/octet-stream. When checking the metadata of the image it does say contentType: 'img/jpeg' in "Other metaData". screenshot

What is going wrong here?



via lvno

No comments:

Post a Comment