How to set Form-data in Rest Message ( attaching a file )

nagendra1891
Kilo Contributor

Hey guys,

I have everything set up and running the only issue is how to set the request of the rest message to ( -F ) form-data

My curl look like this.

curl https:/<endpoint url>/content \
  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \
  -F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
  -F file=@myfile.jpg

this is what causing the problem !!!   the body of the request must be set to -F ( form data )

-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
  -F file=@myfile.jpg

setContent() did not work

Screen Shot 2016-05-13 at 10.36.15 AM.png.

Any help is appreciated!!

regards

Nagendra

22 REPLIES 22

natalliar
ServiceNow Employee
ServiceNow Employee

multipart/form-data is not supported for outbound REST


multiple/form-data is supported. I tested this with HP TRIM for sending files and It worked.


You have to use the following..


Accept = application/json


Content-Type = multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW


Authorization = <if any>



Content =


----WebKitFormBoundary7MA4YWxkTrZu0gW


<Your content>


----WebKitFormBoundary7MA4YWxkTrZu0gW--



Boundary not needed for your post but was required for me to integrate with HP TRIM.


Miki A
Kilo Contributor

I can confirm this working as well !!

Thank you!

Nick65
Mega Expert

I came across the same issue a couple years ago and I ended up writing a small .jar file and deployed it to the Mid server. Passed in the binary and other parameters from a script include to the mid server. Worked great. Java can do this very easily.


I know it's been a few months, but could you show an example of the .jar file script?