我试图上传文件logo.png到皮纳塔IPFS使用curl和php。文档在javacript/Axios中,但正试图在php中完成。
当我运行下面的代码时,它会引发错误。
{"error":{"reason":"KEYS_MUST_BE_STRINGS","details":"pinata_api_key和pinata_secret_api_key必须都是字符串“}}
到目前为止,这里是编码
$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);发布于 2022-10-03 09:18:26
我已经成功地将文件固定在IPFS中,请使用这个.
在ipfs中添加文件fpfs / Pin文件
圆满解决
/** create curl file */
$cFile = curl_file_create($_FILES['logo']['tmp_name'], $_FILES['logo']['type'], $_FILES['logo']['name']);
/** metakey and meta values */
$keyvalues = [
'company' => 'BDTASK',
'background' => '100% Trait',
'Color' => 'RED',
];
/** metadata array */
$metadata = [
'name' => 'This is test file',
'keyvalues' => $keyvalues,
];
/** post data array */
$post = array(
'file' => $cFile,
'pinataMetadata' => json_encode($metadata)
);
/** header info pinata jwt authentication */
$headers = array();
$headers[] = 'Authorization: Bearer pinata-jwt';
$url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
print_r($result); /** Found IPFS CID in here */https://stackoverflow.com/questions/69522161
复制相似问题