title: Uploading file to Digitalocean Spaces with Multer MulterS3 and AWS SDK, NodeJS
body: <p>I'm trying to upload files to my Digitalocean Space using an express API. The log in the below upload method never gets called, and the success status is always returned. In the route req.files the file comes through, but no file is uploaded. I can't find any information that shows a different method of that provides a better result.</p>
  
  <p>My upload route:</p>
  
  <pre><code>const express = require('express');
  const AWS = require('aws-sdk');
  const multer = require('multer');
  const multerS3 = require('multer-s3');
  
  const api = express.Router();
  
  AWS.config.update({
    accessKeyId: process.env.SPACES_ACCESS_KEY_ID,
    secretAccessKey: process.env.SPACES_ACCESS_KEY,
  });
  
  const spacesEndpoint = new AWS.Endpoint('nyc3.digitaloceanspaces.com/uploads');
  const s3 = new AWS.S3({
    endpoint: spacesEndpoint,
  });
  
  const upload = multer({
    storage: multerS3({
      s3,
      bucket: '&lt;my bucket&gt;',
      acl: 'public-read',
      // eslint-disable-next-line
      key: function (req, file, cb) {
        console.log(file);
        cb(null, file.originalname);
      },
    }),
  }).single('upload');
  
  api.post('/', (req, res, next) =&gt; {
    console.log(req.files);
    upload(req, res, err =&gt; {
      if (err) {
        console.log(err);
        return res.status(400).json({ errors: err });
      }
  
      return res.status(200).json({ message: 'File uploaded successfully.' });
    });
  });
  
  module.exports = api;
  </code></pre>
  
  <p>My upload function from the front end using superagent:</p>
  
  <pre><code>request
        .post('http://localhost:5000/api/uploads')
        .attach('upload', &lt;image file&gt;)
        .then(() =&gt; {
          console.log('done');
        });
  </code></pre>