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();
   }
    }


Reply via email to