Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dabit3/ipfs-pinata-example
Example function showing how to pin a file to Pinata from a JavaScript client
https://github.com/dabit3/ipfs-pinata-example
Last synced: 3 months ago
JSON representation
Example function showing how to pin a file to Pinata from a JavaScript client
- Host: GitHub
- URL: https://github.com/dabit3/ipfs-pinata-example
- Owner: dabit3
- Created: 2021-06-28T01:59:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-28T13:35:40.000Z (over 3 years ago)
- Last Synced: 2024-07-27T15:43:39.258Z (3 months ago)
- Size: 0 Bytes
- Stars: 39
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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
```javascript
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
```javascript
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)
}
```