3

I have been trying to upload form-data, but I do not want to send any Content-Type header. I have tried setting

headers: {
           'X-Content-Type-Options': 'nosniff',
           'Content-Type': undefined
         }

But the request still contains

Content-Type:multipart/form-data; boundary=----WebKitFormBoundarykplXRCRn92v5Op52

The code block for reference :

$http({
    url: "/file/",
    method: 'POST',
    data: {
        'file': res
    },
    headers: {
        'Content-Type': undefined
    }
})

I am unable to understand what exactly is happening. Any help would be greatly appreciated.

PS: I understand what is multipart-form data. I just need to strip off that header.

ShivangiBilora
  • 2,382
  • 4
  • 17
  • 26
  • What happens if you use `'Content-Type': 'application/json;charset=UTF-8'` or `'Content-Type': 'text/plain;charset=UTF-8'`? The AngularJS default Content-Type is application/json; When I set the Content-Type to `undefined`, my browser (Chrome) inserts `Content-Type: text/plain;charset=UTF-8 ` – georgeawg Nov 13 '16 at 18:33
  • @georgeawg I tried setting it to 'application/json', but since I am sending multipart form data, it somehow changes the header. And I doubt if its being done by the browser. – ShivangiBilora Nov 15 '16 at 07:06

1 Answers1

0

Check these answers:

What does enctype='multipart/form-data' mean?

Is Content-Type HTTP header always required?

In my opinion these answers solves your problem. If not, paste code that prepares your request.

Community
  • 1
  • 1
Daniel
  • 5,039
  • 2
  • 28
  • 53