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\"
in java code you need to write code like this:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
for more you can refer bellow example and link :-
https://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
The FormData interface provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XHR Send method. It uses the same format a form would use if the encoding type were set to multipart/form-data
.
var formData = new FormData();
formData.append('type', type);
formData.append('description', description);
formData.append('photo', photo);
return $http({
url: PATH_REST_SERVICES + '/nomeServizio',
headers: {"Content-Type": undefined },
data: formData,
method: "PUT"
});
It is important to set the content type header to undefined
. Normally the $http service sets the content type to application/json
. When the content type is undefined
, the XHR API will automatically set the content type to multipart/form-data
with the proper multi-part boundary.