In the process of creating a visual interface that interfaces with various REST services (coded in Java), I am encountering an issue when attempting to call one such service:
@PUT
@Path("serviceName")
public Response serviceName(final FormDataMultiPart multiPart) {
......}
To call the service, I have implemented the following code:
service: function (data) {
return $http({
url: PATH_REST_SERVICES + '/serviceName',
headers: {"Content-Type": "multipart/form-data"},
data: data,
method: "PUT"
});
}
However, upon making the request from my AngularJS service file, I receive error code 400 (bad request) if the service has Content-Type as multipart/form-data.
Alternatively, if the service is set to Content-Types like "application/x-www-form-urlencoded; charset=utf-8" or "application/json; charset=utf-8" or "application/form-data", I encounter a 415 (unsupported media type) error.
As I develop the front-end using JavaScript and HTML5, existing resources online do not address my specific issue as the FormDataMultiPart object doesn't have a Javascript equivalent.
I've attempted to format the data in multiple ways for transmission, consistently resulting in errors 400 or 415.
What would be the correct way to format the data for transmitting in this REST call?
Also, how should the Content-Type field in the headers be configured?