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.
The CustomMetadata
object to be uploaded with the mp3 file per the Custom Metadata documentation. The use case is uploading an APIC
ID3
metadata tag with an mp3's image URL in order to consume by ExoPlayer on Android.
Firebase Console
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.")
}
})
...
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'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With