Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda