uploading a file bigger than Android HEAP size ?

All your problems with Audio, Video and Images.

uploading a file bigger than Android HEAP size ?

Postby zoalord12 » Wed Aug 26, 2009 10:08 am

Hi all,
I am trying to upload a 3.5MB file ...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         try {
  5.  
  6.                         // ------------------ CLIENT REQUEST
  7.  
  8.                        
  9.  
  10.                         FileInputStream fileInputStream = new FileInputStream(new File(
  11.  
  12.                                         exsistingFileName));
  13.  
  14.                         // open a URL connection to the Servlet
  15.  
  16.                         URL url = new URL(urlString);
  17.  
  18.                         // Open a HTTP connection to the URL
  19.  
  20.                         conn = (HttpURLConnection) url.openConnection();
  21.  
  22.                         // Allow Inputs
  23.  
  24.                         conn.setDoInput(true);
  25.  
  26.                         // Allow Outputs
  27.  
  28.                         conn.setDoOutput(true);
  29.  
  30.                         // Don't use a cached copy.
  31.  
  32.                         conn.setUseCaches(false);
  33.  
  34.                         // Use a post method.
  35.  
  36.                         conn.setRequestMethod("GET");
  37.  
  38.                         conn.setRequestProperty("Connection", "Keep-Alive");
  39.  
  40.                         conn.setRequestProperty("Content-Type",
  41.  
  42.                                         "multipart/form-data;boundary=" + boundary);
  43.  
  44.                         dos = new DataOutputStream(conn.getOutputStream());
  45.  
  46.                         Log.e("MediaPlayer", "Headers are written");
  47.  
  48.                         // create a buffer of maximum size
  49.  
  50.                         bytesAvailable = fileInputStream.available();
  51.  
  52.                         bufferSize = Math.min(bytesAvailable, maxBufferSize);
  53.  
  54.                         buffer = new byte[bufferSize];
  55.  
  56.                         // read file and write it into form...
  57.  
  58.                         bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  59.  
  60.                         while (bytesRead > 0) {
  61.  
  62.                                 dos.write(buffer, 0, bufferSize);
  63.  
  64.                                 bytesAvailable = fileInputStream.available();
  65.  
  66.                                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
  67.  
  68.                                 bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  69.  
  70.                         }
  71.  
  72.                         // send multipart form data necesssary after file data...
  73.  
  74.                         // close streams
  75.  
  76.                         Log.e("MediaPlayer", "File is written");
  77.  
  78.                         fileInputStream.close();
  79.  
  80.                         dos.flush();
  81.  
  82.                         dos.close();
  83.  
  84.  
  85.  
  86.                 } catch (MalformedURLException ex) {
  87.  
  88.                         Log.e("MediaPlayer", "error: " + ex.getMessage(), ex);
  89.  
  90.                 }
  91.  
  92.  
  93.  
  94.                 catch (IOException ioe) {
  95.  
  96.                         Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe);
  97.  
  98.                 }
  99.  
  100.  
  101.  
  102.                 // ------------------ read the SERVER RESPONSE
  103.  
  104.                 String str = null;
  105.  
  106.                 try {
  107.  
  108.                         //System.gc();
  109.  
  110.                         inStream = new DataInputStream(conn.getInputStream());
  111.  
  112.                         str = inStream.readLine();
  113.  
  114.  
  115.  
  116.                         // while ((str = inStream.readLine()) != null) {
  117.  
  118.                         // Log.e("MediaPlayer", "Server Response" + str);
  119.  
  120.  
  121.  
  122.                         inStream.close();
  123.  
  124.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


If the file is big it crashes at the line " inStream = new DataInputStream(conn.getInputStream()); " .. if the file is small then it works absolutely fine.


Can someone help me ???? I use eclipse in windows .. how do i increase the heap size to 16M ? there is a way to increase size in linux .. but that directory structure doesnt exist in my android sdk and i cant find the file where you actually write 16MB instead of 4MB.

Anyways .. does anyone know a way to upload huge files ????? what if someone has to upload a file bigger than 16 MB ?
zoalord12
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 17, 2009 1:43 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 7 guests