Skip to main content

Using Storage

You can upload content on IPFS. Starton IPFS is a storage and pinning service, where you can host files, folders, and metadata on our IPFS nodes so that they remain available at all times.

Uploading Files to IPFS

POST requests with a body should have the Content-Type header with value application/json. For sending files it should be multipart/form-data.

   const axios = require("axios")
const FormData = require("form-data")
const fs = require("fs")

// AUTHENTICATING TO THE API USING YOUR API KEY
const startonApi = axios.create({
baseURL: "https://api.starton.com",
headers: {
"x-api-key": "YOUR_API_KEY",
},
})

const buffer = fs.readFileSync("path/of/your/file.extension")
let data = new FormData()
data.append("file", buffer, "filename")
// By setting "isSync" to "true, the request will wait for the pin before completing"
data.append("isSync", "false")

// Optional: you can add metadata on starton to your file
const metadata = JSON.stringify({ your: "additional", meta: "data" })
data.append("metadata", metadata)
startonApi.post("/v3/ipfs/file", data, {
headers: {
"Content-type": `multipart/form-data; boundary=${data.getBoundary()}`,
},
})
.then(res=>console.log(res.data))
.catch(e=>console.log(e))