CodePen
codepen.io › klare › pen › gPQLzy
Pinata
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage. All packages are different, so refer to their docs for how they work. If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing. If active, Pens will autosave every 30 seconds after being saved once.
CodePen
codepen.io › jennifer-elyse › pen › GvvYPE
#dailycssimages Exploding Pinata
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage. All packages are different, so refer to their docs for how they work. If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing. If active, Pens will autosave every 30 seconds after being saved once.
Npmx
npmx.dev › package › @pinata › sdk
@pinata/sdk - npmx
Changes made via this endpoint only affect the metadata for the hash passed in. Metadata is specific to Pinata and does not modify the actual content stored on IPFS in any way. It is simply a convenient way of keeping track of what content you have stored. ipfsPinHash - A string for a valid IPFS Hash that you have pinned on Pinata.
Pinata
pinata.cloud › blog › how-to-quickly-create-an-ipfs-powered-app-with-next-js
How to quickly create an IPFS powered app with Next.js
September 21, 2023 - const saveFile = async (file, fields) => { try { const stream = fs.createReadStream(file.filepath); const options = { pinataMetadata: { name: fields.name, keyvalues: { description: fields.description } }, }; const response = await pinata.pinFileToIPFS(stream, options); fs.unlinkSync(file.filepath); return response; } catch (error) { throw error; } }
Esm
pinia-colada.esm.dev › quick-start.html
Quick Start | Pinia Colada
Queries are the most important feature of Pinia Colada. They are used to declaratively fetch data from an API. Create them with useQuery() in any component. They expect a key to save the data in the cache and a query function that returns the data:
npm
npmjs.com › package › @pinata › sdk
pinata/sdk
August 11, 2022 - Changes made via this endpoint only affect the metadata for the hash passed in. Metadata is specific to Pinata and does not modify the actual content stored on IPFS in any way. It is simply a convenient way of keeping track of what content you have stored. ipfsPinHash - A string for a valid IPFS Hash that you have pinned on Pinata.
» npm install @pinata/sdk
Published: Nov 08, 2022
Version: 2.1.0
Pinata
docs.pinata.cloud › frameworks › astro
Astro - Pinata Docs
import type { APIRoute } from "astro"; import { pinata } from "../../utils/pinata"; export const POST: APIRoute = async ({ request }) => { const data = await request.formData(); const file = data.get("file") as File; if (!file) { return new Response( JSON.stringify({ message: "Missing file", }), { status: 400 }, ); } const { cid } = await pinata.upload.public.file(file); const url = await pinata.gateways.public.convert(cid) return new Response( JSON.stringify({ data: url, }), { status: 200 }, ); };
Medium
medium.com › pinata › a-beginners-guide-to-getting-started-with-the-pinata-node-js-sdk-7430def4e7df
A Beginner’s Guide to Getting Started With The Pinata Node.js SDK | by Kelly Kim | Pinata | Medium
August 1, 2023 - The following blog is a beginner-friendly primer to the features and capabilities of the Pinata Node.js SDK. From concept to execution, following along will equip you with the knowledge to harness the magic of the Pinata SDK to utilize IPFS’s decentralized media distribution and management capabilities.
Top answer 1 of 4
4
It looks like you're attempting to upload a file to the pinJSONToIPFS endpoint, which is intended to purely be used for JSON that is passed in via a request body.
In your situation I would recommend using Pinata's pinFileToIPFS endpoint
Here's some example code based on their documentation that may be of help:
//imports needed for this function
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');
export const pinFileToIPFS = (pinataApiKey, pinataSecretApiKey) => {
const url = `https://api.pinata.cloud/pinning/pinFileToIPFS`;
//we gather a local file for this example, but any valid readStream source will work here.
let data = new FormData();
data.append('file', fs.createReadStream('./yourfile.png'));
return axios.post(url,
data,
{
maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
headers: {
'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
'pinata_api_key': pinataApiKey,
'pinata_secret_api_key': pinataSecretApiKey
}
}
).then(function (response) {
//handle response here
}).catch(function (error) {
//handle error here
});
};
2 of 4
3
The proper code to pin any file to IPFS is as below.
Apparently, even Pinata support staff didn't know this. You need to set an object with the property name filepath as your last parameter. The name doesn't matter, it can be a duplicate, it can be the same as others, or it can be unique.
const url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
const fileContents = Buffer.from(bytes);
const data = new FormData();
data.append("file", fileContents, {filepath: "anyname"});
const result = await axios
.post(url, data, {
maxContentLength: -1,
headers: {
"Content-Type": `multipart/form-data; boundary=${data._boundary}`,
"pinata_api_key": userApiKey,
"pinata_secret_api_key": userApiSecret,
"path": "somename"
}
});
GitHub
github.com › PinataCloud › Pinata-SDK
GitHub - PinataCloud/Pinata-SDK: Official SDK for the Pinata IPFS service · GitHub
August 7, 2024 - Changes made via this endpoint only affect the metadata for the hash passed in. Metadata is specific to Pinata and does not modify the actual content stored on IPFS in any way. It is simply a convenient way of keeping track of what content you have stored. ipfsPinHash - A string for a valid IPFS Hash that you have pinned on Pinata.
Author: PinataCloud
Pinata
pinata.cloud
Pinata | Autonomous File Storage
Add file uploads and retrieval in minutes so you can focus on your app —because you’ve got better things to code than infrastructure.
Stack Overflow
stackoverflow.com › questions › 70202856 › saving-uploaded-file-to-pinata-ipfs-in-nodejs
node.js - Saving uploaded file to Pinata IPFS in NodeJS - Stack Overflow
stream.path = filename; } catch(e) { logger.logError(e); return false; } const options = { pinataMetadata: { name: filename, keyvalues: { context: metadata.context, ownerid: metadata.ownerid } }, pinataOptions: { cidVersion: 0 } }; try { var result = await pinata.pinFileToIPFS(stream, options); console.log("SUCCESS ", result); return result; } catch(e) { logger.logError(e); return null; } res.status(200).json({ success: true, data: 'You got access' }) }); }
DEV Community
dev.to › its_sang › laveraging-pinata-api-to-upload-files-c3i
Laveraging Pinata API to upload files - DEV Community
October 12, 2024 - package main import ( "bytes" "encoding/json" "fmt" "io" "log" "mime/multipart" "net/http" "os" "path/filepath" "sync" "github.com/joho/godotenv" ) const ( maxFileSize = 10 << 20 // 10 MB ) type PinataResponse struct { IpfsHash string `json:"IpfsHash"` PinSize int `json:"PinSize"` Timestamp string `json:"Timestamp"` } type ErrorResponse struct { Error string `json:"error"` } type Credentials struct { Username string `json:"username"` Password string `json:"password"` } func main() { // Load .env file err := godotenv.Load(".env") if err != nil { log.Fatal("Error loading .env file") } // http.Ha