1

I have built an app in Nodejs which uploads file to the DigitalOcean Spaces. I am using multer for the same. When I run it locally on my device, it successfully uploads on DigitalOcean but when I try to upload it after the deploying the app on DigitalOcean, it gives me 404 not found and the above error. I have also uploaded the .aws folder which contains the access key and the secret key and also config file. What do I do?

const aws = require('aws-sdk');
const express = require('express');
const multer = require('multer');
const multerS3 = require('multer-s3');

const app = express();
const spacesEndpoint = new aws.Endpoint('nyc3.digitaloceanspaces.com');
const s3 = new aws.S3({
  endpoint: spacesEndpoint,

});



const upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'imagebr',
    acl: 'public-read',

    key: function (request, files, cb) {

      cb(null, files.originalname);
    }
  })
}).single("image");

app.use(express.static('public'));

app.post('/uploads',upload,(req, res) => {
  res.send('uploaded');
})
app.listen(3001, function () {
  console.log('Server listening on port 3001.');
});     
Mathomania
  • 13
  • 2
  • 4
  • Did you define your AWS credentials in DigitalOcean spaces? In your local device, the credentials are probably defined in your environment, but when running on DigitalOcean you need to configure it first https://docs.digitalocean.com/products/spaces/reference/s3-sdk-examples/#setup-and-configuration – TBA Jan 17 '23 at 04:25
  • Hey @TBA thanks for the comment. Actually now its working. I added the IDs in here only const s3 = new aws.S3({ endpoint: spacesEndpoint, }); – Mathomania Jan 17 '23 at 09:44

0 Answers0