Results 1 to 2 of 2

Thread: Sending files via HTTP (HttpClient)

  1. #1
    Join Date
    Dec 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Sending files via HTTP (HttpClient)

    I've put together code that can send one file at at time via HTTP; when I send more than one at a time the app hangs. It seems that the request entity is sending two different requests, rather than one with multiple files. Anyone know how to resolve this?

    Following is the request entity header info:
    Code:
    --3D6atZKLBPujpCZzClN-wz3AJ0Eh-BBWlRr
    Content-Disposition: form-data; name="imgFile[]"; filename="Inbox_Msg_Display.GIF"
    Content-Type: application/octet-stream; charset=ISO-8859-1
    Content-Transfer-Encoding: binary
    --3D6atZKLBPujpCZzClN-wz3AJ0Eh-BBWlRr--
    
    --A2cG-IXHLNC2Rk7kF3fQ5-bQPQpuDwmUU
    Content-Disposition: form-data; name="imgFile[]"; filename="Table_Msg_Content.GIF"
    Content-Type: application/octet-stream; charset=ISO-8859-1
    Content-Transfer-Encoding: binary
    --A2cG-IXHLNC2Rk7kF3fQ5-bQPQpuDwmUU--
    Below is the code I'm using to create the request entity:
    Code:
    try{
    	for (File selectedFile : selectedFiles){
    	Part[] parts = {new FilePart("imgFile[]", selectedFile)};
    	post.setRequestEntity( new MultipartRequestEntity( parts, post.getParams() ) );
          ...
          ...
          }
    } catch (Exception e) {
          ...
    Last edited by dan0; 03-26-2009 at 02:12 AM.

  2. #2
    Join Date
    Dec 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Figured out the solution, the code should be:

    Code:
    Part[] parts = new Part[selectedFiles.length]
    int index = 0;
    for (File selectedFile : selectedFiles){
      parts[index] = new FilePart("imgFile[]", selectedFile);
      index++;
    }
    The issue was with the I was using the for-loop. I was unnecessarily trying to create inner boundaries as well as an overall boundary for the request entity.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •