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

I've submitted form data with content-type = application/x-www-form-urlencoded and adding the form fields to the HTTP Query Parameters like this:


find_real_file.png


Hi rbeeman   that did not work



i want to set body to form data



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


  -F file=@myfile.jpg



any idea ?


Hey ctomasi



I am trying to make an outbound rest message call which includes a file attachment.



any idea how this can be done ?




any feedback on this is really appreciated



regards


NB


Have you taken a look at this page?



Scripted REST API example - streaming file attachments


yes I have looked into ,


ctomasi


so here is what I am doing



    var postFile =new sn_ws.RESTMessageV2();


  postFile.setEndpoint('https://###################/content');


  postFile.setHttpMethod('post');


  postFile.setRequestHeader('Content-Type','multipart/form-data');


  postFile.setRequestBody('attributes=\'{"name":"tigers.jpeg", "parent":{"id\":"##########"}}');


  postFile.saveResponseBodyAsAttachment('0c1b9818db212200fd283740cf96196f');



  var res=postFile.execute();



i get back 500 response



same call using postman



Screen Shot 2016-09-16 at 9.46.15 AM.png



i get response 200  



the issue is I have to set the content of the   body to form and give them a key value pair.




have gone through every post in the community , I did not see any post which says how to set Form-data    



any help on this is really appreciated  



Regards


NB