I implemented a Rest Service to donwload files from a directory.
**There is my rest service : No problem here **
@GET
@Path("/download")
@Produces("application/zip")
public Response downloadZippedFile() {
File file = new
File("C:/Users/Desktop/Files/201707111513.zip");
ResponseBuilder responseBuilder = Response.ok((Object) file);
responseBuilder.header("Content-Disposition", "attachment;
filename=\"MyJerseyZipFile.zip\"");
return responseBuilder.build();
}
Résult ==> I can download 201707111513.zip from the browser.
-------------------------------------------------
Now, I am trying download multiple .zip files. it causes issues
There is my 2nd rest service : The main problem
@GET
@Path("/download")
@Produces("application/zip")
public Response downloadZippedFile() {
ArrayList<String> PdfInputListFiles = new ArrayList<>();
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111513.zip");
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111514.zip");
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111515.zip");
// to print every file in every PdfInputListFiles
for (String myFile : PdfInputListFiles) {
File file = new File(myFile);
ResponseBuilder responseBuilder = Response.ok((Object) file);
responseBuilder.header("Content-Disposition", "attachment; filename=\"MyJerseyZipFile.zip\"");
return responseBuilder.build();
}
return null;
}
Résult ==> I can ONLY download the first file 201707111513.zip.
And it's normale cause of the return responseBuilder.build() line in the end of For loop.
-------------------------------------------------
Now, I am tryin this :
@GET
@Path("/download")
@Produces("application/zip")
public Response downloadZippedFile() {
ArrayList<String> PdfInputListFiles = new ArrayList<>();
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111513.zip");
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111514.zip");
PdfInputListFiles.add("C:/Users/Desktop/Files/201707111515.zip");
// to print every file in every PdfInputListFiles
for (String myFile : PdfInputListFiles) {
getFile(myFile);
}
return null;
}
public Response getFile(String str) {
// Response response = null;
File file = new File(str);
ResponseBuilder responseBuilder = Response.ok((Object) file);
responseBuilder.header("Content-Disposition", "attachment; filename=\"MyJerseyZipFile.zip\"");
return responseBuilder.build();
}
Résult ==> No download is happen, I can't understand why calling getFile method doesn't return any downloaded file.
**
I need to download evry file in my list, in other words I have multiple paths and I need to download all those files.
SomeOne can help, or suggest an alternative solution !
Thank you