File upload from HTML form via PHP through FileMaker Data API-ThrowExceptions

Exception or error:

I have no more ideas, trying like forever to upload a file from an HTML form into FileMaker via their data API.

Using Postman it works like a charm, no problem. But I am not able to get it up and running in PHP.

Using Postman code as a base, I tried different methods to hand the file over, but nothing works:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://myserver.com/fmi/data/vLatest/databases/myProject/layouts/myLaout/records/".$recordId."/containers/myDatabase/1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('upload'=> new CURLFILE($_FILES['upload']['tmp_name'])),
  CURLOPT_HTTPHEADER => array(
    "Content-Type: multipart/form-data",
    "Authorization: Bearer ".$token,
    "Accept: */*",
    "Cache-Control: no-cache",
    "Host: myserver.com",
    "Accept-Encoding: gzip, deflate, br",
    "Content-Length: ".$fileSize,
    "Connection: keep-alive"
  ),
));

$response = curl_exec($curl);
curl_close($curl);

The above ends with:

response: {"messages":[{"message":"Upload payload must contain a part named 'upload'.","code":"960"}],"response":{}}

Trying to handover a local file just for testing: CURLFILE('/Users/s_brink/temp/3.pdf') ends with no response at all and so on and so on.

Can somebody please help me out how to get this up and running?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *