Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable To Save CustomMetadata in Firebase Cloud Storage With Node.js

Result

In the following code an mp3 file is successfully uploaded to a Firebase Bucket in a Cloud Function using Node.js according to the Extend Cloud Storage with Cloud Functions documentation, similar to the example image transformation. When the mp3 file is selected in the Firebase console or streamed on Android via ExoPlayer it plays as expected. However, the Metadata is not shown as uploaded in Firebase's console.

Expected

The CustomMetadata object to be uploaded with the mp3 file per the Custom Metadata documentation. The use case is uploading an APIC ID3metadata tag with an mp3's image URL in order to consume by ExoPlayer on Android.

Firebase Console

enter image description here

Setup

Note: This is a portion of the full code for brevity.

The metadata location and activity are from the documentation example in order to test whether uploading custom metadata works.

...
.then(() => {
    if (exists === false) {
      return bucket.upload(tempAudioFile, { 
        destination: audioFilePath,  
        metadata: {
          contentType: 'audio/mpeg',
          customMetadata: {
            'location': 'Yosemite, CA, USA',
            'activity': 'Hiking'
          }
        }
      })
    } else {
      throw new Error("Audiocast exists.") 
    }
  })
...
like image 719
Adam Hurwitz Avatar asked Dec 26 '18 18:12

Adam Hurwitz


1 Answers

The Cloud function syntax for custom metadata differs from the frontend library. Instead of customMetadata, use the key metadata. In your case:

metadata: {
    contentType: 'audio/mpeg',
    metadata: {
        'location': 'Yosemite, CA, USA',
        'activity': 'Hiking'
    }
}
like image 80
Ben Xenos Avatar answered Oct 11 '22 03:10

Ben Xenos