I have a script that uploads files to Pinata using cURL & PHP, it works great. But now im trying to pin an entire folder of files. I followed the little instructions they give but get -
[error] => Invalid request format.
Instructions
https://docs.pinata.cloud/pinata-api/pinning/pin-file-or-directory
It says to append files to an array which I do, but it wants the key of the array to be "file" and the array cant have the same key value for multiple files.
Here is my array -
Array
(
[file] => Array
(
[0] => CURLFile Object
(
[name] => 1662838796/playlist0.ts
[mime] =>
[postname] =>
)
[1] => CURLFile Object
(
[name] => 1662838796/playlist1.ts
[mime] =>
[postname] =>
)
[2] => CURLFile Object
(
[name] => 1662838796/playlist2.ts
[mime] =>
[postname] =>
)
)
)
In order to keep "File as the main index I added int keys to each file but still no luck. If I use this single value array it pins the file and works as expected. -
Array
(
[file] => CURLFile Object
(
[name] => 1662838796/playlist2.ts
[mime] =>
[postname] =>
)
)
Any idea where im going wrong here?
cURL Request -
$files = [
'1662838796/playlist0.ts',
'1662838796/playlist1.ts',
'1662838796/playlist2.ts',
];
foreach ($files as $file) {
$postData['file'] = curl_file_create($file);
}
$url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$json = json_decode($result, true);
// returned CID
$hash = $json['IpfsHash'];
** Edit If I remove the "file" and just use index keys I get -
[error] => Unexpected field
Not sure if thats going in the right direction or wrong direction but its a different error so might help find the issue.