Oleg Kalnichevski <[email protected]> writes:

> On Thu, Sep 03, 2009 at 03:04:33PM -0700, Gerald Turner wrote:
>> Oleg Kalnichevski <[email protected]> writes:
>> > Gerald Turner wrote:
>> >> • Multi-part requests in HttpClient 3.x were a little easier to
>> >> work with in a few special cases, the Part interface included the
>> >> ‘name’ field, whereas the ‘name’ field is now a parameter in the
>> >> MultipartEntity.addPart(String,BodyContent) call.
>> >>
>> >>   Before:
>> >>
>> >>     Part[] parts = {
>> >>       new StringPart("Some-Field", "Some-Value"),
>> >>       new FilePart("Some-File", f)
>> >>     };
>> >>
>> >>     MultipartRequestEntity entity =
>> >>       new MultipartRequestEntity(parts, method.getParams());
>> >>
>> >>   After:
>> >>
>> >>     LinkedHashMap<String,ContentBody> parts =
>> >>       new LinkedHashMap<String,ContentBody>();
>> >>     parts.put("Some-Field", new StringBody("Some-Value"));
>> >>     parts.put("Some-File", new FileBody(f));
>> >>
>> >>     MultipartEntity entity = new MultipartEntity();
>> >>     for (Entry<String,ContentBody> part : parts)
>> >>       entity.addPart(part.getKey(), part.getValue());
>> >>
>> >> In some respects I like the API better, but I do have some code
>> >> which needs to assemble the parts (including names) independent of
>> >> the HTTP request execution, so in one application I wrote a Part
>> >> wrapper:
>> >>
>> >>   for (Part part : parts)
>> >>     entity.addPart(part.getName(), part.getContent());
>> >>
>> >
>> > If you can think of a fix for the issue, raise a JIRA.
>> >
>>
>> FormBodyPart does the trick (couples name and content).
>>
>> MultipartEntity.addPart looks like this:
>>
>>   public void addPart(final String name, final ContentBody contentBody) {
>>     this.multipart.addBodyPart(new FormBodyPart(name, contentBody));
>>     this.dirty = true;
>>   }
>>
>> How about an addPart override that looks like:
>>
>>   public void addPart(final BodyPart bodyPart) {
>>     this.multipart.addBodyPart(bodyPart);
>>     this.dirty = true;
>>   }
>>
>
> Raise a JIRA.
>

HTTPCLIENT-874 with patch, thanks.

-- 
Gerald Turner  Email: [email protected]  JID: [email protected]
GPG: 0xFA8CD6D5  21D9 B2E8 7FE7 F19E 5F7D  4D0C 3FA0 810F FA8C D6D5

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to