接入教程
1. 注册Pinata账户并获取API密钥。
2. 使用API上传文件到IPFS网络。
3. 通过返回的CID管理文件。
4. 集成API到您的应用中。
5. 监控文件存储状态。
使用Python上传文件到IPFS
python
import requests
url = 'https://api.pinata.cloud/pinning/pinFileToIPFS'
headers = {
'pinata_api_key': 'YOUR_API_KEY',
'pinata_secret_api_key': 'YOUR_API_KEY'
}
files = {'file': ('example.txt', open('example.txt', 'rb'), 'text/plain')}
response = requests.post(url, headers=headers, files=files)
print(response.json())
使用PHP查询IPFS固定文件
php
<?php
$apiKey = 'YOUR_API_KEY';
$apiSecret = 'YOUR_API_KEY';
$url = 'https://api.pinata.cloud/data/pinList';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'pinata_api_key: ' . $apiKey,
'pinata_secret_api_key: ' . $apiSecret
]);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
使用JavaScript删除IPFS固定文件
javascript
const axios = require('axios');
const url = 'https://api.pinata.cloud/pinning/unpin';
const headers = {
'pinata_api_key': 'YOUR_API_KEY',
'pinata_secret_api_key': 'YOUR_API_KEY'
};
const data = { hashToUnpin: 'QmExampleHash' };
axios.delete(url, { headers, data })
.then(response => console.log(response.data))
.catch(error => console.error(error));
常见问题
Pinata API是否需要付费?
Pinata提供免费和付费套餐。免费套餐有一定限制,如每月上传容量和固定文件数量。付费套餐提供更多功能和更高限制。
Pinata如何确保IPFS文件的持久性?
Pinata通过其专用节点网络固定文件,确保文件在IPFS网络中持续可用。即使原始上传者离线,文件仍可通过Pinata的网络访问。
API密钥在哪里获取?
登录Pinata官网,在用户面板的API密钥部分生成和管理您的API密钥。请妥善保管密钥,不要泄露给他人。
Aitishiku.com