Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
Node Express 404 error when trying to load image uploaded by multer

Im trying to upload images with multer. Everything has worked before on localhost fine. Images get uploaded and i can view them from the url link the code provides. However once i have uploaded it on a server im starting to get this error : "Cannot GET /marketplace-api/rest-api/image/1650484814178.jpg".

I have not provided link to server/domains to the question in case people say thats the problem.

Here is my code:

const express = require('express');
const app = express();
const multer = require("multer");
const path = require("path");
const db = require('./db');
const cors = require('cors');
const port = 5000;
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true , limit: '50mb'}));
app.use(cors());



app.use("/image", express.static("image")); 
let imageName = ""; 
const storage = multer.diskStorage({
  destination: path.join("./image"), 
  filename: function (req, file, cb) {
    imageName = Date.now() + path.extname(file.originalname);
    cb(null, imageName);
  },
});
const upload = multer({
  storage: storage,
  limits: { fileSize: 3000000 },
}).single("myImage");
app.post("/marketplace-api/rest-api/upload-image", (req, res) => {
  upload(req, res, (err) => {
    if (err) {
      console.log(err);
    } else {
      return res.status(201)
      .json({ url: "http://link to domains/marketplace-api/rest-api/image/" + imageName }); 
    }
  });
});
app.listen(port, () => {
  console.log("server run in port", port);
});
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

ok, few things, 1. you dont have any get functions, which means you cant post to this location, i suggest doing this:

app.get('/', (req, res) => {
    res.sendFile(__dirname + "/index.html");
});

and create a file called index.html, go on your site (localhost), and it should work, after that add a form in the html file, it should look something like this

<form action = "/marketplace-api/rest-api/upload-image" method = "POST">
    <input type = "file" name="image">
    <input type = "submit">
</form>

this will add a basic form where you can upload your photo. there are a few more stuff to add / change, i will fix everything and make it a repo then send it here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!