multer icon indicating copy to clipboard operation
multer copied to clipboard

multer.diskStorage - problem with upload file to folder

Open robokonk opened this issue 2 years ago • 2 comments

I have a problem with uploading files to the server with multi. I read documentation and wrote code according to with documentation, but files still are not upload to folder images

My code:

const express = require("express");
const app = express();
const path = require("path");

const multer = require("multer");
const storage = multer.diskStorage({
  desination: "images",
  filename: (req, file, cb) => {
    console.log(file);
    cb(null, Date.now() + path.extname(file.originalname));
  },
});

const upload = multer({ storage: storage });

app.set("view engine", "ejs");

app.get("/upload", (req, res) => {
  res.render("upload");
});

app.post("/upload", upload.single("image"), (req, res) => {
  res.send("Image Uploaded");
});

app.listen(3001);
console.log("3001 is the port");

robokonk avatar May 23 '22 15:05 robokonk

Are you receiving any error? Does the images directory exist relative to the CWD where you are running the app?

LinusU avatar May 29 '22 09:05 LinusU

I have a problem with uploading files to the server with multi. I read documentation and wrote code according to with documentation, but files still are not upload to folder images

My code:

const express = require("express");
const app = express();
const path = require("path");

const multer = require("multer");
const storage = multer.diskStorage({
  desination: "images",
  filename: (req, file, cb) => {
    console.log(file);
    cb(null, Date.now() + path.extname(file.originalname));
  },
});

const upload = multer({ storage: storage });

app.set("view engine", "ejs");

app.get("/upload", (req, res) => {
  res.render("upload");
});

app.post("/upload", upload.single("image"), (req, res) => {
  res.send("Image Uploaded");
});

app.listen(3001);
console.log("3001 is the port");

destination and not desination

ramonpaolo avatar Jun 18 '22 21:06 ramonpaolo