AdamHurwitz
AdamHurwitz

Reputation: 10364

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.") 
    }
  })
...

Upvotes: 7

Views: 1558

Answers (1)

Ben Xenos
Ben Xenos

Reputation: 151

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

Upvotes: 15

Related Questions