Skip to content
Advertisement

Firebase Cloud Storage – upload with metadata –

I wish to upload files from the browser with metadata that will allow the files to be identified and handled correctly with cloud functions.

On the client my uploader code looks like this:

JavaScript

And on the server (Firebase Cloud Functions using Node js)

JavaScript

The uploadHandler is working – but metadata is undefined, as is metadata.metadata

How can I access the metadata that I uploaded from the client?

Advertisement

Answer

You were really close. As per the API reference, the second argument is an UploadMetadata object which has a property called customMetadata.

So, to correct your code, you’d swap out

JavaScript

with

JavaScript

Additionally, your progress logic shouldn’t call resolve and reject like it is at the moment – that’s an antipattern. You should instead chain to UploadTask‘s own Promise API.

JavaScript

With your original code, if getDownloadURL() failed, its error wouldn’t be handled.

If you still want progress reporting, use:

JavaScript
Advertisement