http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[])

<http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[])>in.read()
returns the number of bytes read.  Could it be that the number of bytes
returned from the read is less than the buffer you have allocated?

On Tue, Mar 16, 2010 at 1:59 AM, Alex Luya <[email protected]> wrote:

> I want to upload multiple files by using gwt-google-apis,for example
> an avi file,but Uploaded file become multiple times bigger than
> original file.
>
> in client side, every time,I slice a chunk from Blob by size 20000,and
> send chunk to server ,like this
> ////////////////////////////////////////////////start client code
>        int start=stat.getUploaded();
>        int size=20000;
>        Blob chunk = file.getBlob().slice(start, size);
>
> //get request instance
>        HttpRequest req = Factory.getInstance().createHttpRequest();
>
> // set request
>        req.open("POST", ACTION_URL_FOR_GOOGLE_GEARS);
>        req.setRequestHeader("Slice-Size", Integer.toString(size));
>        req.setRequestHeader("Content-Disposition", "attachment");
>        req.setRequestHeader("Content-Type", "multipart/octet-
> stream");
>
> //send file
>      req.send(chunk);
> //////////////////////////////////////////end of client code
>
>
> in server side,create a byte buffer with chunck size("Slice-
> Size"),read chunk to buffer,then write buffer to file.but written file
> become multiple times bigger than original file.and if without using
> buffer(as commented code),written file is the same as original.So I
> think client side code is ok,problem comes from server side code.Can
> somebody help me to point out,thank you!
> ////////////////////start of server code
> @Override
>    protected void doPost(HttpServletRequest req, HttpServletResponse
> resp)
>            throws ServletException, IOException
>  {
>        InputStream in = req.getInputStream();
>        if (in != null)
>        {
>            String path ="/home/user/upload/test";
>
>            byte[] buffer = new
> byte[Integer.parseInt(req.getHeader("Slice-Size"))];
>            while (in.read(buffer) != -1)
>            {
>                   out.write(buffer);
>            }
>                        int l=0;
>       //     while ((l=in.read()) != -1)
>      //      {
>     //           out.write(l);
>      //      }
>            out.close();
>            in.close();
>   }
>    }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
Eric Z. Ayers
Google Web Toolkit, Atlanta, GA USA
Sign up now for Google I/O 2010: May 19-20, http://code.google.com/io

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" 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/google-web-toolkit?hl=en.

Reply via email to