Skip to content

Unable to send multipart/form-data request #264

Description

@manishchauhanquovantis

Hey,
I need to upload multiple files to my node.js server but when i run
reqwest({ url: url, method: "POST", contentType: "multipart/form-data", data: data, headers: headers }).

It fails to send files to my nodejs API.
Node.JS API
`router.post('/upload', upload.fields([
{ name: 'avatar', maxCount: 1 },
{ name: 'gallery', maxCount: 8 }
]), function(req, res, next) {
res.status(200);
res.send('Successfully uploaded ' + req.files.length + ' files!')
})

I even tried specifying boundry but that even didn't worked

But when i tried with jquery it worked
`
var form = new FormData();
form.append("avatar", "roku project (1).docx");
form.append("asdasd", "asdasd");
form.append("asdasd", "asdasd");

var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:3000/v1/users/upload",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"postman-token": "78a9f343-6b45-82ba-4850-57b6beeed937"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}

$.ajax(settings).done(function (response) {
console.log(response);
});
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions