Usually you login to the API once during a transaction, then use a token for all subsequent requests. $token is a token that the REST API expects as a cookie.The sign in the value tells cURL that we’re dealing with a file. The field name depends on what the API expects it to be. $fields contains an associative array.
You can supply more headers by adding additional values to the array.
Setup a form to submit a fileīefore you can send a binary file to an API, you have to get it from somewhere.
Keep in mind that I’m extracting all of these code snippets from a custom PHP class I wrote, so if you’re working with an API, I’d encourage you to create a class of your own. I was recently working on a project where I had to send and receive binary files to and from a REST API, so I decided to document some of the code I wrote.