Hi all

I want to get from an Android Uri (of the kind returned by
onActivityResult) to a simple byte array, in order to upload a file as
part of a multipart message. Can anyone provide an example of how to
get from a Uri to a byte[] array?

My current code (below) is almost there, but falls down because I
can't work out the LENGTH_OF_FILE from an InputStream. I'd have the
same problem using ByteArrayOutputStream.

I've been looking at the docs on Content Providers
http://developer.android.com/guide/topics/providers/content-providers.html
and wondering if getBlob() is the method I need, but it says it only
applies to small amounts of data (<50KB) and I need to handle larger
files.

thanks!

Current code (doesn't work):

        public static byte[] getBytesFromFile(ContentResolver cR, String
fileUriString) throws IOException {
                Uri tempuri = Uri.parse(fileUriString);
                InputStream is = cR.openInputStream(tempuri);
                byte[] b3 = new byte[LENGTH_OF_FILE];
                is.read(b3);

-- 
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

Reply via email to