I have do do an app that upload the content of a storage card to
a webserver.
Everything is ok for small files but i get Out of Memory for files that are larger > 1,5 MB.
I upload the file as you see below
1) FileConnection srcroot = (FileConnection) Connector.open(path, Connector.READ);
2) hcon = (HttpConnection) Connector.open(formUrl(), Connector.READ_WRITE);
hcon.setRequestMethod(HttpConnection.POST);
hcon.setRequestProperty("Cache-Control", "no-cache");
hcon.setRequestProperty("Content-Type", "application/octet-stream");
is = srcroot.openInputStream();
//open output stream and send contents of byte array
os = hcon.openDataOutputStream();
3)
byte[] data = new byte[bufferSize];
for (int count; (count = is.read(data)) > 0{
os.write(data, 0, count);
//os.flush();
//Runtime.getRuntime().gc();
}
//os.flush()
4) close all connections and streams
I tried different secnarios on commented code with flush, without flush, with gc without gc with different buffer size etc...but no luck on large file (like mp3) ==> OOME ...
What should i do to upload large files from phone with 2MB heap ?
THX

{
Reply With Quote


