简体   繁体   中英

File upload issue in Mongoose

I am using Mongoose 6.18 version as an Embedded Web Server for my project. I have an issue when I try to upload a file to the server. I have a react application on the front end that uses axios api with formdata to send the file. ``

 await axios.post("http://" + window.location.host + "/upload", data, {
      headers: {
        "Content-Type": "multipart/form-data",
        "Content-Length": ""
      }
    }).then((response) => {
      console.log(response);
      console.log(response.data.message);
      alert("File Upload successful"); 
    }, (error) => {
      console.log(error);
      alert("File Upload not successful");
  });

On the server side I am using multipart handling as mentioned in this link. I use the function mg_file_upload_handler. https://cesanta.com/blog/big-upload-example-mongoose-more-than-an-embedded-web-server-2/

By connection closes when the multipart chunks are in progress and every time only a part of file is uploaded. Can someone pls guide me in this.

Please use the latest version instead of an old 6.18, and use of the several upload methods, as described in the tutorial https://mongoose.ws/tutorials/file-uploads/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM