Multi-part upload is not uploading the actual file

957 views
Skip to first unread message

harisha...@gmail.com

unread,
Aug 8, 2017, 8:06:44 PM8/8/17
to REST assured
Hi All,

Below is my code to upload file to a third party service:

Response r = rs.
config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).
urlEncodingEnabled(false).
multiPart(
new File(pathForImage)).
put(uploadURL)
;
return r;

In the above code, I get the response as 200 OK. But the problem here is the actual file is not uploaded. Only the PUT request is made with the empty body.

Have anyone faced this issue earlier?

The only difference here is, I am instructing RA not to add any ContentType using the second line of code(I need to do this because the service that I am using to upload file expects the ContentType to be empty)

Any help is greatly appreciated.

Thanks,
Harisha Talanki

Johan Haleby

unread,
Aug 10, 2017, 1:27:38 PM8/10/17
to rest-a...@googlegroups.com
Maybe you need to specify a different control name? Default is file (see docs).

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

harisha...@gmail.com

unread,
Aug 10, 2017, 4:33:45 PM8/10/17
to REST assured
Hi Johan,

Thanks for your inputs. I updated version of Rest Assured to 2.9.0.

The service that I use is S3 to store my images. Since amazon S3 doesn't expect the charset to be specified, So I use the below code,

config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).

Below is my complete code:

File filetoUpload = new File(pathForImage);
Response r = rs.
config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).
urlEncodingEnabled(false).
        multiPart(filetoUpload)).
put(uploadURL);

but when I run the above, I get the below error: 

java.lang.IllegalArgumentException: Content-Type application/octet-stream is not valid when using multiparts, it must start with "multipart/".

Rest assured is not allowing the content-type application/octet-stream in the header. we have to specify "content-type as multipart/<something>". 

This is where I am stuck. Is there any workaround for this?

Thanks,
Harisha Talanki
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Johan Haleby

unread,
Aug 11, 2017, 3:59:03 PM8/11/17
to rest-a...@googlegroups.com
Well if it's an octet stream it's not a multipart and you should just use "body". I also recommend upgrading to version 3.x. 

/Johan
--
Sent from my phone

Amol Tambe

unread,
Apr 20, 2018, 4:52:38 AM4/20/18
to REST assured
Thanks Johan for your tip. It actually solved my problem. I had almost pulled my hairs out with this issue.

Here is my solution which I got it working finally!.

I was facing same issue and it turned out to be not a multipart upload but through body. Please do not mention the header explicitly as "application/octet-stream". I was able to solve it and got it working successfully with simple code , given(). header("Content-Type","text/csv"). headers("Authorization","bla-blah","Header 2","blahblah"). body(new File("your-file-[ath")). when(). post("/post-url");
Reply all
Reply to author
Forward
0 new messages