title: Uploading a form posted image buffer to Cloud Storage with Firebase Functions
body: <p>Here's my cloud function. It's supposed to get an http posted image and upload it to storage, returning the url.</p>
  
  <pre><code>exports.uploadImageToEditor = functions.https.onRequest((req, res) =&gt; {
          const img = JSON.parse(JSON.stringify(req.body));
          const bucket = admin.storage().bucket();
  
          return bucket.file('blog/foo.jpg').save(img.data, { 
            resumable: false, 
            metadata: { 
              contentType: 'image/jpeg' 
            } 
          })
            .then(() =&gt; {
                return cors(req, res, () =&gt; {
                    res.status(200).send({ "url": bucket.file('foo.jpg').getSignedUrl()});
                  });
              });
      });
  </code></pre>
  
  <p>This is how the image is actually sent in the client:</p>
  
  <pre><code>uploadImage(file, endPoint) {
          if (!endPoint) {
              throw new Error('Image Endpoint isn`t provided or invalid');
          }
          const                  formData = new FormData();
          if (file) {
              formData.append('file', file);
              const                  req = new HttpRequest('POST', endPoint, formData, {
                  reportProgress: true
              });
              return this._http.request(req);
          }
          else {
              throw new Error('Invalid Image');
          }
      }
  </code></pre>