|
| WM21 - download a file slow with httprequest() |
| Iniciado por guest, 02,jun. 2017 15:17 - 4 respuestas |
| |
| | | |
|
| |
| Publicado el 02,junio 2017 - 15:17 |
Hi,
I'm using httprequest() against a simple AWP page to download a file. The file is returned using StringDisplay(). I get the file on the tablet and can save it there fSaveBuffer().
So far so good, I;m using this in an update procedure on the tablet to get updates of my app.
I also tested downloading the apk-file directly form the same webserver. Using the tablet browser. I noticed that downloading a file this way about 10 times faster !! Or you say httprequest() is slooow.
I wonder if that is normal. I would say it is all http-traffic isn't it? |
| |
| |
| | | |
|
| | |
| |
| Publicado el 02,junio 2017 - 20:46 |
Hi Arie,
I haven't tried, so it's just an idea.
Did you try to send the file using FILEdisplay instead of STRINGDisplay...
My reasonning behind this is that in order to send a string, all binary value would probably have to be encapsulated (URLencode or Base64, I would think), while FileDisplay could work in binary mode.
If my supposition is correct, filedisplay should be significantly faster.
Best regards |
| |
| |
| | | |
|
| | |
| |
| Publicado el 03,junio 2017 - 15:41 |
Hi Arie,
Try use other programming languages to build webservice. So far node.js +Express is the fastest. Even with ssl enable + encryption AES128 + base64 encode , still 10 times faster than using AWP |
| |
| |
| | | |
|
| | |
| |
| Publicado el 03,junio 2017 - 17:28 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 09,junio 2017 - 08:33 |
Fabrice,
Filedisplay does not make any difference. I now use this piece of java code , which does do the job fast !
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public static boolean downloadFile(String fileURL, String saveDir) { boolean response; response = false; try { response = downloadTheFile(fileURL, saveDir); } catch (IOException ex) { ex.printStackTrace(); } return response; } public static boolean downloadTheFile(String fileURL, String saveDir) throws IOException { URL url = new URL(fileURL); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); int responseCode = httpConn.getResponseCode(); //String response = new StringBuffer(); StringBuilder response = new StringBuilder(); int bytesRead = -1; byte[] buffer = new byte[4096]; boolean bresult = false; // always check HTTP response code first if (responseCode == HttpURLConnection.HTTP_OK) { String fileName = ""; String disposition = httpConn.getHeaderField("Content-Disposition"); String contentType = httpConn.getContentType(); int contentLength = httpConn.getContentLength(); if (disposition != null) { // extracts file name from header field int index = disposition.indexOf("filename="); if (index > 0) { fileName = disposition.substring(index + 10, disposition.length() - 1); } } else { // extracts file name from URL fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, fileURL.length()); } // System.out.println("Content-Type = " + contentType); // System.out.println("Content-Disposition = " + disposition); // System.out.println("Content-Length = " + contentLength); // System.out.println("fileName = " + fileName); // opens input stream from the HTTP connection InputStream inputStream = httpConn.getInputStream(); if(saveDir != ""){ String saveFilePath = saveDir + File.separator + fileName; // opens an output stream to save into file FileOutputStream outputStream = new FileOutputStream(saveFilePath); while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.close(); } else { while ((bytesRead = inputStream.read(buffer)) != -1) { //Log.d("FBOX", "bytesRead=" + bytesRead); response.append(bytesRead); } } inputStream.close(); bresult = true; } else { Log.d("FBOX",fileURL + " file not downloaded. Server replied HTTP code: " + responseCode); } httpConn.disconnect(); return true; } |
| |
| |
| | | |
|
| | | | |
| | |
|