pedrum golriz
pedrum golriz

Reputation: 512

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
});

Upvotes: 2

Views: 2191

Answers (1)

aleha_84
aleha_84

Reputation: 8539

try:

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

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

Upvotes: 1

Related Questions