Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : Failed to Upload Large files from android
    primarykey
    data
    text
    <p>I need to upload large sized zip file (approx above 10 MB) to server from Android device. I can upload less then 8 MB , while trying to upload above 10 MB it throws "OutOfMemoryError", so I add<br> <code>conn.setFixedLengthStreamingMode(fileInputStream.available());</code> in my code,It also throws the following Exception</p> <pre><code>07-08 10:57:22.649: W/System.err(31383): java.io.IOException: expected 860 bytes but received 4096 07-08 10:57:22.649: W/System.err(31383): at libcore.net.http.FixedLengthOutputStream.write(FixedLengthOutputStream.java:39) 07-08 10:57:22.649: W/System.err(31383): at java.io.DataOutputStream.write(DataOutputStream.java:98) 07-08 10:57:22.649: W/System.err(31383): at com.ams.utilities.PhotoUploadAsyncTask.doInBackground(PhotoUploadAsyncTask.java:273) 07-08 10:57:22.649: W/System.err(31383): at com.ams.utilities.PhotoUploadAsyncTask.doInBackground(PhotoUploadAsyncTask.java:1) 07-08 10:57:22.656: W/System.err(31383): at android.os.AsyncTask$2.call(AsyncTask.java:287) 07-08 10:57:22.656: W/System.err(31383): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 07-08 10:57:22.656: W/System.err(31383): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 07-08 10:57:22.664: W/System.err(31383): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 07-08 10:57:22.672: W/System.err(31383): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 07-08 10:57:22.688: W/System.err(31383): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 07-08 10:57:22.703: W/System.err(31383): at java.lang.Thread.run(Thread.java:856) </code></pre> <p>the following code i use to Upload Zip file</p> <pre><code>DataOutputStream os = null; HttpsURLConnection conn = null ; String strBoundary = "---------------------------14737809831466499882746641449"; String endLine = "\r\n"; conn = (HttpsURLConnection) new URL(url).openConnection(); if(fileInputStream != null) conn.setFixedLengthStreamingMode(fileInputStream.available()); conn.setRequestMethod("POST"); conn.setRequestProperty( "Content-Type", "multipart/form-data;boundary="+strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Accept", "text/xml"); conn.connect(); os = new DataOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary +endLine).getBytes()); os.write((encodePostBody(postData, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); os.write(("Content-Disposition: form-data; name=\"cloud_photos\"; filename=\"cloud_photos.zip\"" + endLine).getBytes()); os.write(("Content-Type: application/octet-stream" + endLine + endLine).getBytes()); if(fileInputStream != null){ long lengthOfFile = zipfilePath.length(); //fileInputStream.available();// int bytesAvailable = fileInputStream.available(); int maxBufferSize = 4 * 1024; LogAMS.d(TAG, "bytesAvailable="+bytesAvailable); int bufferSize = Math.min(bytesAvailable, maxBufferSize); byte[] buffer = new byte[bufferSize]; int total = 0; // read file and write it into form... int bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead &gt; 0){ total += bytesRead; os.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); int progress = (int)((total*100) / lengthOfFile); if(progress &lt;= 98){ if(progress % 20 == 0) publishProgress(progress); }else{ if(progress == 99) publishProgress(progress); } bufferSize = Math.min(bytesAvailable,maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } } } os.write((endLine + "--" + strBoundary + endLine).getBytes()); // fileInputStream.close(); os.flush(); os.close(); os = null; return parseUploadResponse(conn.getInputStream()); </code></pre> <p>I need to upload it in chunks.If anyone could give me a suggestions as to the best approach, I would be very grateful.</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload