I use NanoHTTPD as web server in my Android app.
I pass two file names from client browser to NanoHTTPD server, and I hope to download the two files at a time, but the following code only download the file1, and the file2 isn't downloaded.
How to download two or multiple files at a time?
public class MyWebServer extends NanoHTTPD
{
private final String rootDir;
public MyWebServer(int port, String rootDir)
{
super("192.168.1.4", port);
this.rootDir = rootDir;
}
@Override
public Response serve(IHTTPSession session)
{
Map<String, String> parms = session.getParms();
String filename1=GetFilename(parms);
String filename2=GetFilename(parms);
File file1 = new File(rootDir + filename1);
File file2 = new File(rootDir + filename2);
return downloadFile(file1);
return downloadFile(file2);
}
private Response downloadFile(File file)
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(file);
} catch (FileNotFoundException ex)
{
Logger.getLogger(MyWebServer.class.getName()).log(Level.SEVERE, null, ex);
}
return newFixedLengthResponse(Response.Status.OK, "application/octet-stream", fis, file.getTotalSpace());
}
@Override
public Response newFixedLengthResponse(IStatus status, String mimeType, String message)
{
Response response = super.newFixedLengthResponse(status, mimeType, message);
response.addHeader("Accept-Ranges", "bytes");
return response;
}
}