I'm a bit puzzled why the other respondents didn't pick up this, maybe I missed something in the discussion?
But anyway, the basic flaw in your strategy is reading it all into memory at once. There's no need to do so, and that is ALWAYS going to impose a limit on the size of file you can handle, on any platform. Instead of reading all your data, and then stufffng it into a ByteArrayOutputStream, and pulling out a *HUGE* array -- The simplest strategy: Open an output stream to your server, and simply copy from the camera to the server. That has the fatal drawback that the camera will be tied up, and possibly blocked, if the server is too slow -- which is likely. So that's not really a viable strategy. So you need something to stand in for the server. The only viable option is a file on the SD card. So open a temporary output file, rather than a byte-array output stream, and write it there. Then, instead of getting a byte array, re- open your SD card file, and copy from that file to the server. Under no circumstances, in no programing environment, do you ever want to buffer a file of unknown size in memory. If you wanted to be extremely clever, you could simultaneously transfer to the SD card, and transfer from the SD card to the net. But extreme cleverness is seldom very smart. I wonder why the multipart stuff was left out of the SDK? I hadn't noticed that. These little holes and omissions and using-obsolete- versions thing I find rather disorienting -- you think you know what's there, then BAM -- not on the Android, unless you BYO Code. On Apr 8, 1:58 pm, Anna PS <annapowellsm...@googlemail.com> wrote: > Apologies for cross-posting with StackOverflow, but I'm getting a bit > desperate. I'll cross-post any final answer too. > > Please could anyone suggest an approach for transferring a >2MB video > from a ContentResolver into a Bytestream, without running out of > memory? > > See > question:http://stackoverflow.com/questions/2599305/android-outofmemoryerror-w... > > Here's the current code, which throws an OutOfMemoryError on the > byteBuffer.write(buffer, 0, len) line when transferring large videos: > > // get bytestream to upload > videoByteArray = getBytesFromFile(cR, fileUriString); > > public static byte[] getBytesFromFile(ContentResolver cR, String > fileUriString) throws IOException { > Uri tempuri = Uri.parse(fileUriString); > InputStream is = cR.openInputStream(tempuri); > byte[] b3 = readBytes(is); > is.close(); > return b3;} > > public static byte[] readBytes(InputStream inputStream) throws > IOException { > ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); > // this is storage overwritten on each iteration with bytes > int bufferSize = 1024; > byte[] buffer = new byte[bufferSize]; > int len = 0; > while ((len = inputStream.read(buffer)) != -1) { > byteBuffer.write(buffer, 0, len); > } > return byteBuffer.toByteArray(); > > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en