hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benson Margulies <bimargul...@gmail.com>
Subject Re: Multipart Mixed
Date Fri, 03 Jun 2016 19:49:39 GMT
Here's what I coded. It's not a patch, just code you're welcome to,
but it's probably much like yours.

private void setupMultipartRequest(final DocumentRequest request,
final ObjectWriter finalWriter, HttpPost post) {

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMimeSubtype("mixed");
    builder.setMode(HttpMultipartMode.STRICT);

    FormBodyPartBuilder partBuilder = FormBodyPartBuilder.create("request",
            // Make sure we're not mislead by someone who puts a
charset into the mime type.
            new
AbstractContentBody(ContentType.parse(ContentType.APPLICATION_JSON.getMimeType()))
{
                @Override
                public String getFilename() {
                    return null;
                }

                @Override
                public void writeTo(OutputStream out) throws IOException {
                    finalWriter.writeValue(out, request);
                }

                @Override
                public String getTransferEncoding() {
                    return MIME.ENC_BINARY;
                }

                @Override
                public long getContentLength() {
                    return -1;
                }
            });

    // Either one of 'name=' or 'Content-ID' would be enough.
    partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"request\"");
    partBuilder.setField("Content-ID", "request");

    builder.addPart(partBuilder.build());

    partBuilder = FormBodyPartBuilder.create("content", new
InputStreamBody(request.getContentBytes(),
ContentType.parse(request.getContentType())));
    partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"content\"");
    partBuilder.setField("Content-ID", "content");
    builder.addPart(partBuilder.build());
    builder.setCharset(StandardCharsets.UTF_8);

    HttpEntity entity = builder.build();
    post.setEntity(entity);
}



On Fri, Jun 3, 2016 at 2:21 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> On Thu, 2016-06-02 at 12:52 +0200, Stefan Magnus Landrø wrote:
>> Hi there,
>>
>> We're struggeling with some limitations in the current multipart
>> implementation in 4.5 (latest).
>>
>> The MultipartEntityBuilder is actually building a MultipartFormEntity,
>> whereas we actually want to be able to build a multipart/mixed entity which
>> does have limitations with respect to filesize as defined in
>> MultipartFormEntity.
>>
>> We're considering improving the MultipartEntityBuilder in such a way that
>> it can also produce MultipartMixedEntity (new type)
>>
>> Oleg, any comments?
>>
>
> Stefan
>
> I am not sure I fully understand the issue but you are welcome to submit
> a patch with changes you deem necessary.
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

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


Mime
View raw message