noahdubs
noahdubs

Reputation: 89

Req.file returns [object, object] when trying to upload picture using multer and cloudinary

I am trying to save an image from a form using multer and cloudinary but the only thing that gets returned in the request.file and request.body is [object, object]

my app.js file

const multer = require("multer");
const cloudinary = require("cloudinary");
const cloudinaryStorage = require("multer-storage-cloudinary");

cloudinary.config({
    cloud_name: process.env.CLOUD_NAME,
    api_key: process.env.API_KEY,
    api_secret: process.env.API_SECRET 
});
const storage = cloudinaryStorage({
    cloudinary: cloudinary,
    folder: "demo",
    allowedFormats: ["jpg", "png"],
    transformation: [{ width: 500, height: 500, crop: "limit" }]
});
const parser = multer({ storage: storage });

app.post("/", parser.single("image"), (req, res)=>{
  console.log(req.file) // <--- this returns [object, object]
 }
  

html form

<form action="/" method="post" encType="multipart/form-data">
  <input type="file" name="image" />
</form>

Upvotes: 1

Views: 1943

Answers (1)

Nathan Hawks
Nathan Hawks

Reputation: 587

Your form doesn't have a file-uploader doohicky. Change the type of your input to file instead of text and then try.

Also, when you want to inspect an object via console.log you should do:

console.log( JSON.stringify( theObject ) );

Upvotes: 2

Related Questions