Skip to content

Example function showing how to pin a file to Pinata from a JavaScript client

Notifications You must be signed in to change notification settings

dabit3/ipfs-pinata-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

An example of how to pin a file to IPFS with Pinata in a JavaScript app

If you're like me and had no luck finding any examples or code to show how this is done, then hopefully this will help you.

Pinning a string

async function save() {
  let ipfs = await IPFS.create({
    url: "https://api.pinata.cloud/psa",
    repo: 'file-path' + Math.random()
  })
  const { cid } = await ipfs.add('hello world')
  const url = `https://gateway.pinata.cloud/ipfs/${cid.string}`
  console.log(url)
}

Pinning a file

async function onChange(e) {
  const file = e.target.files[0]
  let ipfs = await IPFS.create({
    url: "https://api.pinata.cloud/psa",
    repo: 'file-path' + Math.random()
  })
  const { cid } = await ipfs.add(file)
  const url = `https://gateway.pinata.cloud/ipfs/${cid.string}`
  console.log(url)
}

About

Example function showing how to pin a file to Pinata from a JavaScript client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published