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 Indodroid. On Sat, Apr 10, 2010 at 12:19 AM, Anna Powell-Smith < annapowellsm...@googlemail.com> wrote: > > > On 9 April 2010 19:35, Anna Powell-Smith > <annapowellsm...@googlemail.com>wrote: > >> >> >> On 9 April 2010 18:19, Gubatron <gubat...@gmail.com> wrote: >> >>> I suppose when you say FilePart, you mean this >>> >>> org.apache.commons.httpclient.methods.multipart.FilePart >>> >>> I'm thinking along these lines after looking at that API (I haven't >>> tested this) >>> >>> final File theFile = new File("yourFileLargerThan2Mb.ext"); >>> >>> //Implement your own PartSource to feed your File >>> PartSource partSource = new PartSource() { >>> //this should return a buffered reader... right? >>> public InputStream createInputStream() { >>> return BufferedInputStream (new FileInputStream(theFile)); >>> } >>> >>> //implement the other methods of the interface >>> public String getFileName() { >>> return theFile.getName(); >>> } >>> >>> public long getLength() { >>> return theFile.length();// although this might be how much is >>> left on the stream, not sure. >>> } >>> >>> } >>> >>> FilePart part = FilePart(theFileName, partSource); >>> >>> then use your part on your multipart request. >>> >> >> 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(), >> "myfile.gif"); >> 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. >> > > 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. > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://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