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-while-uploading-video-how-best-to-chunk 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 at http://groups.google.com/group/android-developers?hl=en