title: Google Cloud Functions - Upload to Google Cloud Storage via HTTP
body: <p>I'm attempting to handle file uploads using a Google Cloud Function. This function uses Busboy to parse the multipart form data and then upload to Google Cloud Storage.</p>
  <p>I keep receiving a <code>ERROR: { Error: ENOENT: no such file or directory, open '/tmp/xxx.png'</code> error when triggering the function.</p>
  <p>The error seems to occur within the <code>finish</code> callback function when storage.bucket.upload(file) attempts to open the file path <code>/tmp/xxx.png</code>.</p>
  <p>Example code</p>
  <pre><code>const path = require('path');
  const os = require('os');
  const fs = require('fs');
  const Busboy = require('busboy');
  const Storage = require('@google-cloud/storage');
  const moment = require('moment');
  const _ = require('lodash');
  
  const projectId = 'xxx';
  const bucketName = 'xxx';
  
  
  const storage = new Storage({
    projectId: projectId,
  });
  
  exports.uploadFile = (req, res) =&gt; {
    if (req.method === 'POST') {
      const busboy = new Busboy({
        headers: req.headers
      });
      const uploads = []
      const tmpdir = os.tmpdir();
  
      busboy.on('file', (fieldname, file, filename, encoding, mimetype) =&gt; {
        const filepath = path.join(tmpdir, filename)
        var obj = {
          path: filepath,
          name: filename
        }
        uploads.push(obj);
  
        var writeStream = fs.createWriteStream(obj.path);
        file.pipe(writeStream);
      });
  
      busboy.on('finish', () =&gt; {
        _.forEach(uploads, function (file) {
  
          storage
            .bucket(bucketName)
            .upload(file.path, {
              name: moment().format('/YYYY/MM/DD/x') + '-' + file.name
            })
            .then(() =&gt; {
              console.log(`${file.name} uploaded to ${bucketName}.`);
            })
            .catch(err =&gt; {
              console.error('ERROR:', err);
            });
  
  
          fs.unlinkSync(file.path);
        })
  
        res.end()
      });
  
      busboy.end(req.rawBody);
    } else {
      res.status(405).end();
    }
  }
  </code></pre>