Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. React
  4. React : POST http://localhost:8081/upload 500 (Internal Server Error) and Request failed with status code 500

React : POST http://localhost:8081/upload 500 (Internal Server Error) and Request failed with status code 500

Scheduled Pinned Locked Moved React
2 Posts 2 Posters 65 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paradox02
    wrote last edited by
    #1

    Client.js
    const uploadUpload = async (e) => {
    e.preventDefault();
    const formdata = new FormData();
    formdata.append("imageFile", image);
    try {
    console.log(image);

    await axios({
    method: "POST",
    url: "http://localhost:8081/upload",
    headers: { "content-type": "multipart/form-data" },
    data: formdata, // Try this line
    });
    } catch (err) {
    console.log("ERROR", err);
    }};
    Server.js

    const storage =......
    const upload = multer({
    storage: storage,
    }).single("imageFile");
    app.post("/upload", upload, async (req, res) => {
    const image = req.file.filename;
    const sql = "INSERT INTO imageTable (imgeName) VALUES (?)";
    db.query(sql, [image], (err, result) => {
    if (err) return res.json({ Message: "ERROR INSIDE SERVER" });
    return res.json(result);
    });
    console.log(imageFile.filename);
    });

    The name of the image is saved in the database, the image has been uploaded to the 'public/image' folder, but it gives me the errors
    POST http://localhost:8081/upload 500 (Internal Server Error) and Request failed with status code 500

    1 Reply Last reply
    0
    • realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote last edited by realJSOP
      #2

      The best thing i can tell you is to open up dev tools in your browser, nd look at the network tab and inspect the payload and response that comes back from the db server.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups