I think you are on the right track. I have had very similar problems in the past. For me the temporary file solution was obvious because I had to modify the media before I uploaded it. Once you have a temporary file, then you have the generic problem of uploading a large file to a web server, and you aren't using don't need any Android specific code.
It also makes it much easier if there are interstitial pages, multiple activities client side that will need to access the temporary media file, (perhaps to display a preview), and you can handle low memory conditions better. The more Android development I do the more I find myself writing to private local storage, to make sure I never lose state. On Apr 21, 9:02 am, Android Development <[email protected]> wrote: > 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 < > > > > > > [email protected]> wrote: > > > On 9 April 2010 19:35, Anna Powell-Smith > > <[email protected]>wrote: > > >> On 9 April 2010 18:19, Gubatron <[email protected]> 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 [email protected] > > To unsubscribe from this group, send email to > > [email protected]<android-developers%2Bunsubs > > [email protected]> > > 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

