title: How to upload the images to s3 bucket using nodejs?
body: <p>I am new to aws. I want upload an image from node js using multer to s3 bucket.</p>
  
  <p>I have followed the tutorial on youtube but am getting stuck with this error.</p>
  
  <p><a href="https://www.youtube.com/watch?v=ASuU4km3VHE&amp;t=1047s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=ASuU4km3VHE&amp;t=1047s</a></p>
  
  <p>TypeError: Cannot read property 'location' of undefined" error.(POSTMAN)</p>
  
  <p>Please help me figure out the problem.Thank you for help</p>
  
  <p>file_upload.js</p>
  
  <pre><code>const express = require("express");
  const app = express();
  const upload = require("./file_upload");
  
  const singleUpload = upload.single("image");
  
  app.post("/image-upload", function(req, res) {
    singleUpload(req, res, function(err, some) {
      if (err) {
        return res.status(422).send({
          errors: [{ title: "Image Upload Error", detail: err.message }]
        });
      }
      return res.json({ imageUrl: req.file.location });
    });
  });
  
  
  app.listen(3000, () =&gt; {
    console.log("Listening on Port 3000");
  });
  </code></pre>
  
  <p>file_upload_router.js</p>
  
  <pre><code>const multer = require("multer");
  const multerS3 = require("multer-s3");
  const aws = require("aws-sdk");
  
  aws.config.update({
    secretAccessKey: "Your_ACCESS_KEY",
    accessKeyId: "YOUR_ACCESS_KEY_ID",
    region: "" // region of your bucket
  });
  
  const s3 = new aws.S3();
  
  const upload = multer({
    storage: multerS3({
      s3: s3,
      bucket: "upload-image-node-test",
      acl: "public-read",
      metadata: function(req, file, cb) {
        cb(null, { fieldName: "TESTING_META_DATA!" });
      },
      key: function(req, file, cb) {
        cb(null, Date.now().toString());
      }
    })
  });
  
  module.exports = upload;
  </code></pre>
  
  <p>I have also made the below changes:-</p>
  
  <p>Block new public ACLs and uploading public objects (Recommended)" to False.</p>
  
  <p>"Remove public access granted through public ACLs (Recommended)" to False too.﻿</p>
  
  <p>I need to get a JSON response with the imageUrl as key and timestamp as filename but i am getting the below error:</p>
  
  <p>TypeError: Cannot read property 'location' of undefined"</p>