简体   繁体   中英

Empty file request payload on post and empty filename for form-data

I have a multipart form where the first part of the request is the form data and the second part is a file. The first part of the request is missing a filename and the second part has an empty payload where the binary contents should show.

A sample payload is as follows:
------WebKitFormBoundaryiCmJmbQ7e518oDt9
Content-Disposition: form-data; name="message"

{"category":"OTHER","subject":"Test","body":"testttt"}
------WebKitFormBoundaryiCmJmbQ7e518oDt9
Content-Disposition: form-data; name="test.pdf"; filename="test.pdf"
Content-Type: application/pdf


------WebKitFormBoundaryiCmJmbQ7e518oDt9-- 

The first content-disposition is missing filename="message". I've tried changing this into a Blob, but then the payload is empty. No matter what I try, I can't get the file to show in the payload. It should show something like PDF

My ajax request:

var data = new FormData();
data.append('message', JSON.stringify(message.attributes));
data.append(document.getElementById('fileInput').files[0].name,document.getElementById('fileInput').files[0]);
message.save({},{
    cache: false,
    contentType: false,
    processData: false,
    data: data
});

try:

message.save(null,{
    cache: false,
    contentType: false,
    processData: false,
    data: data
});

also here is question about backbone file upload. And another solution.

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