What do you mean readBytes never gets set to -1? Is the code going
into an infinite loop? Or are you stepping though it in a debugger. In
the later case, it would take a *very* long time for readBytes to be
set to -1 because you are reading and writing one byte at a time.
I am not sure if this is the problem or not, but try using a buffer to
transfer data from the input stream to the output stream:
final int BUFFER_SIZE = 1024*4; // 4k buffer
byte[] temp = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = buf.read(temp, 0, BUFFER_SIZE)) != -1) {
os.write(temp, 0, bytesRead);
}
On Mar 18, 7:13 pm, Tejas <[email protected]> wrote:
> Hi,
>
> I'm trying to read an image (taken on camera) that I need to POST to a
> server.
> I'm using the following code:
>
> <CODE>
> OutputStream os = urlConn.getOutputStream();
>
> ContentResolver cR = this.getContentResolver();
> InputStream is = cR.openInputStream(photoUri);
> BufferedInputStream buf = new BufferedInputStream(is);
> int readBytes = 0;
>
> while ((readBytes = buf.read()) != -1){
> os.write(readBytes);
> }
>
> </CODE>
>
> But when I debug, I find that readBytes never gets a -1 (i.e eof). Can
> anyone tell what is wrong here?
> Is there any other alternative to read photos taken by the phone
> camera (get a stream or bytes) to be POSTed to services etc...
>
> Cheers,
> Tej
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---