i am trying to have a REST service return a zip file from the local harddrive . Following is what i am doing ,
@Path("/interface3/{Ent_id}/{esf_app_id}/{esf_app_ver}")
public class Interface3Mock {
// This method is called if TEXT_PLAIN is request
@GET
@Produces("application/zip")
public Response callInterface3_text(
@PathParam("Ent_id") Integer entitlement_id,
@PathParam("eapp_id") String eapp_id,
@PathParam("eapp_ver") String eapp_ver) {
File f = new File("D:\\Documentation\\Documentation.zip");
String mt = new MimetypesFileTypeMap().getContentType(f);
return Response.ok(f, mt).build();
}
}
Now when i use the browser ie. Internet Explorer and key in the url http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345
i see a file download dialog that says "Do you want to save the file l345`.
i want it to ask me for the zip download ie. D:\\Documentation\\Documentation.zip
.
But somehow it takes up the last parameter in the request URL.
Using Postman to upload Files If you are using Postman to test your REST Services, all you need to do is create a New | HTTP request. From the HTTP Request UI: Enter the URL of the REST Service (f.e. http://localhost:8080/rest-file-manager/resr/file/upload ) Select POST as method.
To attach a file, you must include it with the Body as form-data. Once you are in the Body → form-data fields, you must enter a KEY . This should be “file” or whichever value you specified in the @RequestPart(“[value]”) . After doing so, a dropdown will appear that gives you the option of Text or File.
A MediaType constant representing ""application/json"" media type. static String. APPLICATION_OCTET_STREAM. A String constant representing ""application/octet-stream"" media type.
Download file using Rest Assured programRight-click on the target file (here, minions. zip). If you enter the above URL in the browser, the browser automatically starts downloading the file. So lets write the code to hit the above URL endpoint with our Rest Assured code.
return Response.ok(f, mt)
.header("Content-Disposition", "attachment; filename=Documentation.zip")
.build();
See How to set response header in JAX-RS so that user sees download popup for Excel?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With