Friday, 11 November 2016

javascript - How to use AngularJS $http to send multipart/form-data

I am developing a graphical interface that uses different services rest (written in java).
I have to call up a service like this:



@PUT
@Path("nomeServizio")
public Response nomeServizio(final FormDataMultiPart multiPart) {

......}


Call service:



service: function (data) {

return $http({
url: PATH_REST_SERVICES + '/nomeServizio',
headers: {"Content-Type": "multipart/form-data"},

data: data,
method: "PUT"
});
}


When I request from my Angularjs service file I get: error 400 (bad request) if the service has a Content-Type = multipart / form-data



While I get a 415 (unsupported media type) error if the service has a Content-Type = "application / x-www-form-urlencoded; charset = utf-8" or "application / json; charset = utf-8" or "application / form-data ".




I am developing the front-end in javascript and html5, I did not find anything in the web that can help me as the FormDataMultiPart object does not exist in javascript.



I tried to format the data to send in many ways but it always returns 400 or 415.



How should I format the data to send to the rest call?



And how should the Content-Type be in the headers?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...