2

I am using apache httpclient 4.2 to send Multipart HTTP PUT request. The client has to upload large size binary data of the order of 500 MB. Hence compression is required. I wish to compress the whole Multipart HTTP request and inform the server through header Content-Encoding: gzip. I control the server as well as client code.

Note: I am aware of the approach where I can selectively compress the large size binary data & not the whole request but for now I am ruling out that approach.

The httpclient's HttpRequestInterceptor class doesn't provide a handle to the request input stream or an entity to compress the request.

I have searched on the web & found few related links(below) but none of them works 1. http://old.nabble.com/compressing-multipart-request-from-custom-client-tt27804438.html#a27811350 2. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#protocol_interceptors - This link says that "Protocol interceptors can also manipulate content entities enclosed with messages - transparent content compression / decompression being a good example." but don't know how to get the desired functionality.

Please give me some direction, if possible some sample code.

1 Answer 1

2

I was finally able to solve this requirement by

  1. creating a org.apache.http.entity.mime.MultipartEntity object reqEntity.
  2. Adding the compressed binary part to the HTTP request

    ByteArrayBody binaryData = new ByteArrayBody(compressedData, "binary/octet-stream", "N/A"); binaryParts.add(binaryData); reqEntity.addPart("uniqueId", binaryPart);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.