Eduardo, Alex, you guys rock!  A very, very happy new year to you guys.

On Tuesday, November 26, 2013 9:10:03 AM UTC-8, Eduardo Martins Barbosa 
wrote:
>
> Great solution, Alex.
>
> But it stopped working for me after I upgraded to Angular 1.2.2.
>
> To fix it, just change Content-Type to undefined instead of false.
>
> var payload = new FormData();
> // populate payload
> $http.post(postUrl, payload, {
>   headers: { 'Content-Type': undefined },
>   transformRequest: function(data) { return data; }
> });
>
>
> On Monday, October 21, 2013 10:49:09 PM UTC-2, Jason Hostetter wrote:
>>
>> You were the last piece of the puzzle of at least 2 hours of googling. 
>> Thank you good sir.
>>
>> On Sunday, January 13, 2013 12:55:19 PM UTC-5, alex wrote:
>>>
>>> more precisely, you'd do this (just tested it myself):
>>>
>>> var payload = new FormData();
>>> // populate payload
>>> $http.post(postUrl, payload, {
>>>   headers: { 'Content-Type': false },
>>>   transformRequest: function(data) { return data; }
>>> });
>>>
>>> Default Content-Type is application/json if I'm not mistaken, and you 
>>> can't set it manually to e.g. 'multipart/whatever' because if you're 
>>> POSTing binary data (e.g. images) you'll need a boundary ID. Not setting 
>>> Content-Type will make the underlying XHR browser implementation add a 
>>> correct header, 'type; boundary'.
>>>
>>>
>>> On Sunday, January 13, 2013 5:04:52 PM UTC+1, alex wrote:
>>>>
>>>> $HttpProvider's default request transform function looks like this:
>>>>
>>>> // transform outgoing request data
>>>> transformRequest: [function(d) {
>>>>   return isObject(d) && !isFile(d) ? toJson(d) : d;
>>>> }],
>>>>
>>>> and isFile(d) basically tests that d.toString() === '[object File]'. 
>>>> so, angular is trying to tranform your formdata with toJson() which won't 
>>>> work I guess.
>>>>
>>>> You could make $http.post() work with formdata by overriding the 
>>>> tranform function, e.g.:
>>>>
>>>> $http.post(url, myformdata, {
>>>>   transformRequest: function(data) { return data /* data here is 
>>>> myformdata */ }
>>>> })
>>>>
>>>>
>>>> On Wednesday, August 8, 2012 10:14:54 AM UTC+2, David Krutky wrote:
>>>>>
>>>>> I know about this, but you can't pass FormData object into jQuery 
>>>>> param function and without param function it doesn't work either. I was 
>>>>> thinking maybe a different header than urlencoded form? But I have no 
>>>>> idea 
>>>>> which one. What I am trying to do here is send FormData object, not just 
>>>>> the usual data.
>>>>>
>>>>> On Tuesday, August 7, 2012 10:38:15 PM UTC+2, [email protected]:
>>>>>>
>>>>>> $http.post takes a 3rd parameter, a config object.  So try doing this:
>>>>>>
>>>>>> $http.post(url, jQuery.param(payload), {
>>>>>>   headers:{
>>>>>>      'Content-Type':'application/x-www-form-urlencoded'
>>>>>>    }
>>>>>> }); 
>>>>>>
>>>>>> http://docs.angularjs.org/api/ng.$http#post<http://www.google.com/url?q=http%3A%2F%2Fdocs.angularjs.org%2Fapi%2Fng.%24http%23post&sa=D&sntz=1&usg=AFQjCNGMfTVTgO0CJeaBmehwFIwtx5w8aw>
>>>>>>  
>>>>>>
>>>>>> This is not clear at all without doing a lot of reading or 
>>>>>> familiarity with class hierarchy.
>>>>>>
>>>>>> On Monday, August 6, 2012 4:38:02 AM UTC-7, (unknown) wrote:
>>>>>>>
>>>>>>> Anyone knows how to use FormData object with $http service? Because 
>>>>>>> this doesn't seem to work:
>>>>>>>
>>>>>>> var payload = new FormData();
>>>>>>> payload.append("CustomField", "This is some data");
>>>>>>> $http.post(url, payload);
>>>>>>>
>>>>>>> Result from this is post with an empty object. Maybe set header to 
>>>>>>> somethink else?
>>>>>>>
>>>>>>> The reason I am using FormData is, that it can let you easily upload 
>>>>>>> files.
>>>>>>>
>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to