OutOfMemoryError: how best to transfer large video files into a byte array?

by Abdul Mateen » Fri, 09 Apr 2010 05:31:45 GMT

Sponsored Links
 I got the same problem, when I uploaded the videos to Facebook, I have got
the same issue while uploading big files, have you found any workarround,
even I flushed the outstream on every read. but it did not also seems be the


OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 00:44:27 GMT


Because it's the only way that I know to get from a content Uri to the byte
array that I use to create the FilePart element of the multipart message.

It is possible to create the FilePart element using a File object (this
handles even a 50MB file successfully, though it takes around half an hour
to create, so I don't fancy using it in practice). However, I can't work
from a File object, because I have to use the content Uri that is returned
by ACTION_VIDEO_CAPTURE. Originally I did pass a File Uri as extra output to
ACTION_VIDEO_CAPTURE, but that unfortunately breaks the 'retake' and
'delete' buttons on the video camera.

Thanks, but please could you explain what you mean by that? Perhaps with an

Mark warned that creating buffers tends to clog up memory. Indeed, after
increasing the buffer size to 1MB, as he predicted, I can now handle files
up to about 5MB.


Sponsored Links

OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 02:35:46 GMT


Thanks. Constructing a FilePart from a File is actually as easy as this, I
think - but do you think your method would provide some advantage?

    File temp_file = new File(Environment.getExternalStorageDirectory(),
    FilePart vFile = new FilePart("fileupload", temp_file);

As I say, this works for files of 50MB. The only reason I can't use it is
that I can't construct a File object from an Android content Uri. I have to
use an Android content Uri because that's what the video intent returns.


OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 02:49:46 GMT


Ah. If I could transform my content Uri into FileInputStream (will have to
experiment) then I could use your method.

I can convert a content Uri to an InputStream already, so it'll just be
getting from an InputStream to a FileInputStream that might be the
challenge. I'll experiment.


OutOfMemoryError: how best to transfer large video files into a byte array?

by Android Development » Thu, 22 Apr 2010 00:03:11 GMT

 Select a fixed buffer size first.

Then start writing the byte array to a file. Once the file size reaches the
buffer size configured, copy that file to a temporary location (a temp
file). Then transfer this temp file to the web server. Once transferred
successfully, make sure to delete this temp file (by calling deleteOnExit()
) when the file was created.

To make this work properly, there have to be 2 threads at work  - the thread
that is writing the byte array to a file and the thread that is doing the
heavy duty stuff in the background - copy to the temp file location and
finally upload it to a server etc. This heavy duty thread waits on a
condition (waits for the file to reach the buffer size configured to start
the transfer).

I hope this makes sense...just sharing my thoughts aloud.

Best Regards

On Sat, Apr 10, 2010 at 12:19 AM, Anna Powell-Smith <


Other Threads

1. batere mulai boros..battery use paling banyak android system

para suhu dan suhi,
mohn masukannya yah..aku pake x10 mini pro tapi akhir2 ini pemakaian
baterai boros sekali dan yang terbanyak adalah bergantian phone idle
dan display. biasanya tahan dr pagi sampai jam 7 malam,sekarang jam
2-3 siang sudah habis. anehnya kalau malam saya tinggal tidur dia
malah cepat sekali habis.apakah push mail yg masuk dan LED yg nyala
akibat itu menghabiskan banya batere? saya sudah hapus applikasi yang
katanya boros batere tapi juga tidak berpengaruh. kalo saya buat
browsing juga sekarang cepat sekali berkurang baterenya. apakah opera
mini 6 dan launcher pro 0.85 boros batere? saya pilih refresh manual
utk twitter dan fb,tidak aktif utk ym kalo saya tidak perlu. apa  saya
juga pakai app battery detail utk info kalo sudah full rechargenya
tapi akhir2 ini notifnya gak jalan. apakah pengaruh dari masalah
batere saya? saya sudah wipe battery status tapi juga gak ada
perubahan. apa lg yang mesti saya lakukan?


2. Cannot get sound to play from notification

I'm trying to get a notification to make a asound, asny sound.  The
notification comes up, but no sound....

NotificationManager manger = (NotificationManager)

    Notification notification = new Notification(R.drawable.icon,
"Teeth Alert", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(gContext,
0, new Intent(gContext, NotifyMessage.class), 0);
    notification.setLatestEventInfo(gContext, "Your teeth
appoitmernt:", "Date:", contentIntent);

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;



3. Downloading other applications from a stub

4. Question about Android 2.2/2.3 and Hardware accelerated graphics

5. Android app crashes when invoking getSystemService(LOCATION_SERVICE)

6. deleting old apps

7. What exactly happens during an upgrade?