Help Converting cURL to CFHTTP
I'm hoping I'm missing something obvious here and this will be a simple fix.
I'm working with the LinkedIn API, specifically creating a share.
I've got all the authentication working and have successfully created plain text and article shares. However, in order to include an image with a share I'm hitting a snag.
According to the documentation, after making an initial call to obtain the uploadUrl, you then upload the file. Specifically: "To upload your image, send a POST request to the uploadUrl with your image included as a binary file."
It gives this cURL example:
curl -i --upload-file /Users/peter/Desktop/superneatimage.png --header "Authorization: Bearer redacted" 'https://api.linkedin.com/mediaUpload/blahblahblah'
I have tried numerous ways to replicate this call with CFHTTP, but LinkedIn always returns a 400 Bad Request response. No other info.
Here's my latest try:
<cfhttp url="#uploadURL#" method="post" result="uploadRes" multipart="true" multipartType="form-data">
<cfhttpparam type="header" name="Authorization" value="Bearer #accessToken#">
<cfhttpparam type="header" name="X-Restli-Protocol-Version" value="2.0.0">
<cfhttpparam type="file" file="#pathtoPNGfile#" name="imgFile" mimetype="image/png">
</cfhttp>
I have been able to assemble a cURL request like the example and it works fine. Returns a 201 Created response. Using the same data in CFHTTP gives the 400 response.
I am by no means a cURL expert so my question is:
- --upload-file, I'm unclear how this is working in cURL.
- is it the same as CFHTTPPARAM type=File?
- should I be converting the image to binary and send through the body?
Ideas?
