Pinata Docs
Search…
Pin File or Directory
/pinning/pinFileToIPFS
This endpoint will accept a single file or a single directory. The request must include a read stream for the payload in order for the API to accept it.

Uploading and Pinning a Single File

Each upload can optionally include additional information beyond just the file. Both pinataOptions and pinataMetadata can be included in the request. Their formats are documented here.
post
https://api.pinata.cloud
/pinning/pinFileToIPFS
cURL
Node.js
Python
Go
curl --location --request POST 'https://api.pinata.cloud/pinning/pinFileToIPFS' \
--header 'Authorization: Bearer PINATA JWT' \
--form '[email protected]"/Users/Desktop/images/cat.JPG"' \
--form 'pinataOptions="{\"cidVersion\": 1}"' \
--form 'pinataMetadata="{\"name\": \"MyFile\", \"keyvalues\": {\"company\": \"Pinata\"}}"'
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('file', fs.createReadStream('/Users/Desktop/images/cat.JPG'));
data.append('pinataOptions', '{"cidVersion": 1}');
data.append('pinataMetadata', '{"name": "MyFile", "keyvalues": {"company": "Pinata"}}');
​
var config = {
method: 'post',
url: 'https://api.pinata.cloud/pinning/pinFileToIPFS',
headers: {
'Authorization': 'Bearer PINATA JWT',
...data.getHeaders()
},
data : data
};
​
const res = await axios(config);
​
console.log(res.data);
import requests
​
url = "https://api.pinata.cloud/pinning/pinFileToIPFS"
​
payload={'pinataOptions': '{"cidVersion": 1}',
'pinataMetadata': '{"name": "MyFile", "keyvalues": {"company": "Pinata"}}'}
files=[
('file',('cat.JPG',open('/Users/Desktop/images/cat.JPG','rb'),'application/octet-stream'))
]
headers = {
'Authorization': 'Bearer PINATA JWT'
}
​
response = requests.request("POST", url, headers=headers, data=payload, files=files)
​
print(response.text)
​
package main
​
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
​
func main() {
​
url := "https://api.pinata.cloud/pinning/pinFileToIPFS"
method := "POST"
​
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("/Users/Desktop/images/cat.JPG")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("file",filepath.Base("/Users/Desktop/images/cat.JPG"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
_ = writer.WriteField("pinataOptions", "{\"cidVersion\": 1}")
_ = writer.WriteField("pinataMetadata", "{\"name\": \"MyFile\", \"keyvalues\": {\"company\": \"Pinata\"}}")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
​
​
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
​
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Bearer PINATA JWT")
​
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
​
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Uploading and Pinning a Directory

This endpoint also allows users to pin an entire directory to IPFS. This works almost identically to pinning a file, with the main difference being that we provide an array of files and need to provide a relative file path for each file in the directory.
However, our servers will use the exact path that's provided for each file, so it's important that each path begins with the "base" directory that is being uploaded. As an example, if your directory is located at "./../myBuilds/desiredBuild" on your local machine, then each file path should start with "desiredBuild".
We have a JavaScript example of uploading a directory below. Note that in the example, we use the got library instead of axios, but the same general procedure can be applied using axios or any other library.
Last modified 2mo ago