You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Vitor Isaia <vi...@gmail.com> on 2006/09/08 15:13:00 UTC

multipart byte[] post

Hello!

This is my first message in the list. I need to do a file upload, in
packages, via http to a server. So, I split the file in 100 packages,
each package represented by a byte[] and converted do base64 to be
posted. So, the file content is being sent in a http post. But for
every post I do (for the whole upload, there is a total of 100 posts)
the server's memory increases a lot, even if I don't process anything
(just by leaving the servlet's doPost method empty). So, in a forum
someone told me to send it multipart. But beacause I'm sending it in
packages, I need to send each byte[] in a multipart way. I don't know
how to do that. I tried this:

private void sendPackage(byte[] pack) throws Exception
{
      this.postMethod = new PostMethod(this.host);
      Part[] parts =
      {
            new FilePart("pack", new  ByteArrayPartSource("content", pack))
      };

      this.postMethod.setRequestEntity(new
MultipartRequestEntity(parts, this.postMethod.getParams()));
      this.httpClient.executeMethod(this.postMethod);
      this.postMethod.releaseConnection();
      parts = null;
}

Is this right?? Am I missing something? This method is called a
hundred times in the client.
PS.: In the servlet's side I try to parse the request with the Commons
FileUpload library, but I got errors when the parseRequest method is
called, like internal NullPointerExceptions.

Any suggestions? Thanks a lot for any help...

Vitor Isaia

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: multipart byte[] post

Posted by Vitor Isaia <vi...@gmail.com>.
Hello Roland!
Thanks for the answers. I know I can't leave the doPost method empty,
I did it just for test purpose, to be sure the problem was in the
post, not in the server process. I split by myself because we've
created a transfer protocol for security reasons, so the client do
some info interchange. But now I solved my problem, I'm using a
InputStreamRequestEntity, worked fine.
Thanks!

On 9/8/06, Roland Weber <ht...@dubioso.net> wrote:
> Hello Vitor,
>
> why do you split the file yourself? HttpClient will transfer
> a file in chunks of digestable size, and it is transparently
> recombined on the server.
> You can't just leave the doPost method unimplemented. You've
> got to read the data that is sent to the server!
>
> cheers,
>   Roland
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: multipart byte[] post

Posted by Roland Weber <ht...@dubioso.net>.
Hello Vitor,

why do you split the file yourself? HttpClient will transfer
a file in chunks of digestable size, and it is transparently
recombined on the server.
You can't just leave the doPost method unimplemented. You've
got to read the data that is sent to the server!

cheers,
  Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org