anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

TypeError: Cannot read property 'location' of undefined #109

Closed ronaldl29 closed 6 years ago

ronaldl29 commented 6 years ago

Here is my code:

// AWS
AWS.config.update({
  accessKeyId: "XXX",
  secretAccessKey: "XXX"
});
const s3 = new AWS.S3();
const bucket = 'XXX';
const upload = multer({
    storage: multerS3({
      s3,
      bucket,
      // Set public read permissions
      acl: 'public-read',
      // Auto detect content type
      contentType: multerS3.AUTO_CONTENT_TYPE,
      // Set key/filename as original uploaded name
      key: (req, file, cb) => {
        cb(null, `${Date.now().toString()}-${file.originalname}`);
      },
    }),
  });

app.post('/addphotos/:propertyid', upload.single('image'), function(req, res, next) {
    res.send('Successfully uploaded at ' + req.file.location + '.');
});

When sending a file to this route, I am getting this error:

TypeError: Cannot read property 'location' of undefined

LinusU commented 6 years ago

When sending a file to this route, [...]

How are you sending the file?

ronaldl29 commented 6 years ago

I feel very dumb. I was just missing "enctype='multipart/form-data'" in the HTML form.

nishant1596 commented 5 years ago

Thank you @ronaldlong46

KrishnaKaladharGopu commented 3 years ago

I have got the same error, but I didn't understand how to rectify....