1

Am trying to upload files logo.png to Pinata IPFS using curl and php. The Documentation is in javacript/Axios but am trying to do it in php

Pinata Docs

When I run the code below, it throws error

{"error":{"reason":"KEYS_MUST_BE_STRINGS","details":"pinata_api_key and pinata_secret_api_key must both be strings"}}

here is coding so far

$url = "https://api.pinata.cloud/pinning/pinFileToIPFS"; // Where to upload file to
   $data = array(
       'pinata_api_key' => '00xxxxxx',
    'pinata_secret_api_key' => 'e1xxxxxxxxxxxxxxxxxxcccccccc');

$file = 'logo.png';
$data['file'] = $file;

//$data = new CURLFile($file, mime_content_type($file));
//file_get_contents();

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
echo $result = curl_exec($handle);

if (curl_errno($handle)) {
  echo "CURL ERROR - " . curl_error($handle);
}

else {
  // $info = curl_getinfo($handle);
  // print_r($info);
  echo $result;
}


curl_close($handle);
   
Nancy Moore
  • 2,005
  • 2
  • 15
  • 31
  • Does this answer your question? [how to upload file using curl with PHP](https://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php) – Justinas Oct 11 '21 at 07:01
  • 2
    According to the API documentation, `pinata_api_key` and `pinata_secret_api_key` must both be send as request headers, you tried to send them as parameters in the request body instead. – CBroe Oct 11 '21 at 07:11
  • Its the Header issue. As **CBroe** Suggested. I send `pinata_api_key` and `pinata_secret_api_key` as request headers and it works. – Nancy Moore Oct 12 '21 at 01:51

0 Answers0