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.
On Apr 9, 12:43 pm, Anna Powell-Smith <[email protected]>
wrote:
> > Why are you reading the entire file into a byte array?
> > That sounds right there like the OutOfMem error.
>
> 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.
>
> > when you're about to do your multipart post just read a little, write
> > a little. Buffer the sending process,
>
> Thanks, but please could you explain what you mean by that? Perhaps with an
> example?
>
> 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.
--
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
To unsubscribe, reply using "remove me" as the subject.