0

I am trying to use the new Facebook Messenger Platform API to send image message using image file from application directory.

Facebook gives the example using cURL like below:

curl  \
  -F recipient='{"id":"USER_ID"}' \
  -F message='{"attachment":{"type":"image", "payload":{}}}' \
  -F filedata=@/tmp/testpng.png \
  "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

But I am trying to use the API with C#. For your information, I have successfully use the API if I use the file from an internet url.

I have tried to fill in the filedata property by using base64 string of the image file, but unsuccessful.

Kindly explain how does cURL works with the given file path especially image and create a POST request to the web server? And if possible, what options do I have to do it with C#?

hendryanw
  • 1,819
  • 5
  • 24
  • 39

1 Answers1

1

The -F option is for form. This is equivalent to issuing a POST request with the Content-Type header of multipart/formdata and the request body containing all the key-value pairs listed with a proper boundary set. cURL will read the binary data and put the bytes in the correct boundary in the request. There are many examples online for C# to submit a multipart/formdata request. Look into HttpClient or WebClient file uploads and you'll find what you need.

I'll be away from a computer for a few days and submitting sample code from a mobile device isn't the easiest thing to do. If you need some sample code, let me know.

ManOVision
  • 1,853
  • 1
  • 12
  • 14
  • 1
    additional information to create multipart/formdata request is on answer link : http://stackoverflow.com/a/19664927/2601922 – hendryanw May 01 '16 at 10:08