iron-ajax
iron-ajax copied to clipboard
Implement multipart/form-data
Wouldn't implementing multipart/form-data be rather trivial?
The current code reads:
_encodeBodyObject: function(body, contentType) {
if (typeof body == 'string') {
return body; // Already encoded.
}
var bodyObj = /** @type {Object} */ (body);
switch(contentType) {
case('application/json'):
return JSON.stringify(bodyObj);
case('application/x-www-form-urlencoded'):
return this._wwwFormUrlEncode(bodyObj);
case('multipart/form-data'):
var fd = new FormData;
// Totally untested, but it would need to check what's in body
for(var k in bodyObj ) fd.append(k, bodyObj[ k ] );
return fd;
}
return body;
},
...or something "along those lines"?
Heya, @mercmobily, that sounds like a pretty great idea! Would you mind submitting a PR? My only requests would be to put curly braces around the for loop's contents and writing a few tests.
Thanks!
I need this feature, so I will be happy to write a PR. Tackling the issue, I need to make sure I get it right in terms of adding the file fields to FormData. But it's not too hard. Is there any way you could assign this to me, so that I don't lose it? I should get to it in a week or so...
Thanks for the interest, @mercmobily, unfortunately our team hasn't set up a collaborators team on Github yet so I can't assign this issue to you. How about forking the repo, creating an issue on the fork, and assigning yourself there?
Hi,
Yep, will do. Good point, silly me...
Merc.
On 14 July 2016 at 08:46, Elliott Marquez [email protected] wrote:
Thanks for the interest, @mercmobily https://github.com/mercmobily, unfortunately our team hasn't set up a collaborators team on Github yet so I can't assign this issue to you. How about forking the repo, creating an issue on the fork, and assigning yourself there?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PolymerElements/iron-ajax/issues/219#issuecomment-232527353, or mute the thread https://github.com/notifications/unsubscribe/ACB7XnbyOa4Bztx0stng8PyMLlKBDrRXks5qVYb7gaJpZM4JIorq .
https://github.com/mercmobily/iron-ajax/issues/1
Probably would also want a case where if the body is an instanceof FormData
then it doesn't try to rebuild it? I guess if we used a for..of loop it wouldn't make a difference other than the overhead of recreating the FormData object?