Pinata提供了友好、直观的用户界面和API,方便用户在 IPFS上创建和管理内容。
Getting Started - Pinata Docshttps://docs.pinata.cloudPinata提供了上传文件和上传文件夹的API
Nodejs:
//imports needed for this function const axios = require('axios'); const fs = require('fs'); const FormData = require('form-data'); const basePathConverter = require('base-path-converter'); const url = `https://api.pinata.cloud/pinning/pinFileToIPFS`; const src = './image'; const pinataApiKey = 'XXXXXX'; const pinataSecretApiKey = 'XXXXXX'; var files = [ './image/001.jpg', './image/002.jpg' ]; let data = new FormData(); files.forEach((file) => { data.append(`file`, fs.createReadStream(file), { filepath: basePathConverter(src, file) }); }); const metadata = JSON.stringify({ name: 'testname' }); data.append('pinataMetadata', metadata); console.log(data.getBuffer()) axios.post(url, data, { maxBodyLength: 'Infinity', headers: { 'Content-Type': `multipart/form-data; boundary=${data._boundary}`, pinata_api_key: pinataApiKey, pinata_secret_api_key: pinataSecretApiKey } }) .then(function (response) { console.log(response) }) .catch(function (error) { console.log(error) });
Python:
import requests url = 'https://api.pinata.cloud/pinning/pinFileToIPFS' pinataApiKey = 'XXXXXXX' pinataSecretApiKey = 'XXXXXXX' files = [ ('file', ("image/001.jpg", open('./image/001.jpg', 'rb'))), ('file', ("image/001.jpg", open('./image/001.jpg', 'rb'))) ] data = { "name": "testname" } headers = { "pinata_api_key": pinataApiKey, "pinata_secret_api_key": pinataSecretApiKey } r = requests.post(url, data, files = files, headers=headers) print(r.content)
Curl:
curl -F "file=@image/001.jpg;filename=image/001.jpg" -F "file=@image/002.jpg;filename=image/002.jpg" -F "name=testname" "https://api.pinata.cloud/pinning/pinFileToIPFS" -H "pinata_api_key:XXXXX" -H "pinata_secret_api_key:XXXXXX"