I have tried, with normal ajax page without ember, and my file did got uploaded to server. With the same headers on server side.
When I am sending file from normal ajax page following header is sent
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryLIXMQovu3QtpydB1
But when sent from Ember it is
Content-Type:application/json;charset=utf-8
May be this is the issue? and how to resolve that?
I did some experiments and changed the content-type: multipart/form-data
in ember component. Now it is giving me
XMLHttpRequest cannot load http://localhost:8000/api/demopages. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Which clearly is not the case as there are header present in the API, and which is working fine when sending a request outside the ember. So far as what I understand is something with Ember which is changing the outgoing request. Not sure.
Following request is sending proper data to server, but if I takeout form-urlencoded
from header then server dont receive any thing
Ember.$.ajax({
url: 'http://localhost:8000/demopage',
data: {id: 1, title: 'Two'},
type: 'POST',
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
},
});
So logically I shouldnt have to set that x-www-form-urlencoded
content type.