On 01/27/2011 01:28 AM, sree_at_work_at_yahoo.com wrote:
> Hi Paul,
>
> I am stuck at the last 'important notes',
> " Each of the boundary separators has 2 more dashes than the boundary
> value specified in the Content-Type header "
>
> Another difference, I found is,
> formDataMultiPart.field("image_upload", file,
> MediaType.APPLICATION_OCTET_STREAM_TYPE);
> results on wire as,
> Content-Type: application/octet-stream
> Content-Disposition: form-data; name="image_upload"
> <image binary>
>
> This misses to add { filename="logo_big.png" }, how can I make it
> appear, on wire ?
>
you can use FileDataBodyPart..
FormDataMultiPart fdmp = new FormDataMultiPart();
fdmp.bodyPart(new FileDataBodyPart("file-attachemnt", new
File("/Users/pavel/.bashrc")));
WebResource wr = resource();
wr.addFilter(new LoggingFilter());
ClientResponse cr =
wr.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,
fdmp);
produces:
1 > POST
http://localhost:9998/helloworld-webapp
1 > Content-Type: multipart/form-data
--Boundary_1_107049838_1296130454267
Content-Type: application/octet-stream
Content-Disposition: form-data; filename=".bashrc"; name="file-attachemnt"
or "regular" FormDataMultiPart, its Builder has .filename() method. See
[1].
Pavel
[1]
http://jersey.576304.n2.nabble.com/Java-equivalent-of-curl-F-td3815109.html
> Please help ?
>
>
> Code:
> FormDataMultiPart formDataMultiPart = new
> FormDataMultiPart();
> // formDataMultiPart.type("--" +
> "----------------------------d8b4f160da95");
> formDataMultiPart.field("image_upload", file,
> MediaType.APPLICATION_OCTET_STREAM_TYPE);
> formDataMultiPart.field("api_key", CLIENT_API_KEY);
> formDataMultiPart.field("date", date);
> formDataMultiPart.field("nonce", nonce);
> formDataMultiPart.field("limit", LIMIT_RESULTS);
> formDataMultiPart.field("api_sig", api_sig);
>
> ClientResponse response =
> webResource
> .type(SEARCH_CONTENT_TYPE_HEADER)
>
> .accept(MediaType.APPLICATION_JSON_TYPE)
> .post(ClientResponse.class,
> formDataMultiPart);
>
>
>
> TCPMon:
> ==================
> POST /rest/search/ HTTP/1.1
> Content-Type:
> multipart/form-data;boundary=----------------------------d8b4f160da95
> Accept: application/json
> MIME-Version: 1.0
> User-Agent: Java/1.7.0-ea
> Connection: keep-alive
> Content-Length: 7900
>
>
> ------------------------------d8b4f160da95
> Content-Type: application/octet-stream
> Content-Disposition: form-data; name="image_upload"
>
> <image binary>
>
> ------------------------------d8b4f160da95
> Content-Type: text/plain
> Content-Disposition: form-data; name="api_key"
>
> 1CMUPjlfBm*vL9ZvSqJO
> ------------------------------d8b4f160da95
> Content-Type: text/plain
> Content-Disposition: form-data; name="date"
>
> 1296087167
> ------------------------------d8b4f160da95
> Content-Type: text/plain
> Content-Disposition: form-data; name="nonce"
>
> 1296087167680
> ------------------------------d8b4f160da95
> Content-Type: text/plain
> Content-Disposition: form-data; name="limit"
>
> 10
> ------------------------------d8b4f160da95
> Content-Type: text/plain
> Content-Disposition: form-data; name="api_sig"
>
> b4ace490e38a89ca721878ded1ef5846f5f4c516
> ------------------------------d8b4f160da95--
> ==============================
>
> Thanking you, in advance.
>
> With Regards
> Sree
>
>