Topics

How do i upload a file using form-data?

Srikanth Hugar <srikanth.hugar@...>
 

Hello,

    I would like to write a REST client to upload a document using form data.

I tried multiple options options, but could not help.

REST CLIENT fails:
 self.class.post(path, :documentName => File.new('E:\code\css\trunk\qa\dev-test\resources\webrtc_overview.pptx'), :json => '{"ownerId":"59c1393f69d05905dcfc8993c0c659fd","outputType":"PDF"}', :headers => headers, :multipart => true )


from above request, server throws the error.


My postman request headers which is successful looks something like below:

SUCCESS from POSTMAN 

Content-Type:multipart/form-data
Request Payload
------WebKitFormBoundarydvTARb1P7x7rBdOA
Content-Disposition: form-data; name="documentName"; filename="webrtc_overview.pptx"
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation

------WebKitFormBoundarydvTARb1P7x7rBdOA
Content-Disposition: form-data; name="json"
{"ownerId":"59c1393f69d05905dcfc8993c0c659fd","outputType":"PDF"}