title: Firebase Cloud Storage - upload with metadata -
body: <p>I wish to upload files from the browser with metadata that will allow the files to be identified and handled correctly with cloud functions.</p>
  <p>On the client my uploader code looks like this:</p>
  <pre><code>    uploadTaskPromise: async function (file) {
        return new Promise((resolve, reject) =&gt; {      
          const storageRef = storage.ref();
          const myRef = storageRef.child(`myfolder/${my_file_name}.wav`);
          const metadata = {
            project_id: my_project_id
          };
         
          const uploadTask = myRef.put(file, { metadata: metadata });    
          uploadTask.on(&quot;state_changed&quot;,(snapshot) =&gt; {
            const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
            console.log(&quot;Upload is &quot; + progress + &quot;% done&quot;);            
           },   
           function error(err) {
             console.log(&quot;error&quot;, err);
             reject();
            }, 
            function complete() {
            uploadTask.snapshot.ref.getDownloadURL()
            .then(function (downloadURL) {
               resolve(downloadURL);
             });
           }    
         )
       });
     },
  </code></pre>
  <p>And on the server (Firebase Cloud Functions using Node js)</p>
  <pre><code>exports.uploadHandler = functions.storage.object().onFinalize(async (object) =&gt; { 
    const bucket = admin.storage().bucket(object.bucket);
    const metadata = await bucket.file(object.name).getMetadata()
    console.log(&quot;METADATA: &quot; + JSON.stringify(metadata))
   
    // THIS IS WHERE I WANT TO HANDLE UPLOADS BASED ON THE METADATA
    
    return ({ message: &quot;file uploaded&quot; })
  });
  
  </code></pre>
  <p>The <code>uploadHandler</code> is working - but <code>metadata</code> is <code>undefined</code>, as is <code>metadata.metadata</code></p>
  <p>How can I access the metadata that I uploaded from the client?</p>