You can use Starton to integrate blockchain into your application in a few steps. Let's upload a file from Code with Starton's API.
not a developer?
To follow this tutorial, you will need coding experience. If it's not your case, you can still upload your files:
Step 1 - Initialize the project
-
Start by creating a directory for your project.
mkdir upload-ipfs
-
Then, get into your project directory.
cd upload-ipfs
-
With your project directory set up, install the dependencies.
npm add axios form-data
-
Then, use
touch
to create aindex.js
file and open it with your favorite editor.touch list.js
Step 2 - Add starton to your project
-
First, import
axios
.const axios = require("axios")
-
Then, initialize
axios
using Starton URL and authenticate with your API KEY.
Create an API key
const starton = axios.create({
baseURL: "https://api.starton.com",
headers: {
"x-api-key": "YOUR API KEY",
},
})
Step 3 - Upload a file to IPFS
Watch your uploads
Files on IPFS are immutable and can be widely replicated. Once uploaded, anyone can access your file and removal is almost impossible challenging. Think twice before sharing!
-
Grab any file from your computer. You can also generate an image using generative AI.
const fs = require("fs")
const FormData = require("form-data")
const buffer = fs.readFileSync("./path/of/your/file.png") -
Prepare the file for the request.
let data = new FormData()
data.append("file", buffer, "name of your file") -
Send the file to IPFS.
starton
.post("/v3/ipfs/file", data, {
headers: {
"Content-type": `multipart/form-data; boundary=${data.getBoundary()}`,
},
})
.then((response) => {
console.log({
cid: response.data.cid,
gatewayUrl: `https://eu.starton-ipfs.com/ipfs/${response.data.cid}`,
})
})
.catch((error) => console.error(error.response.data))You can also upload folders, JSON files or pin existing files using their CID.
-
Almost done! Now we can execute it to get your first file stored on IPFS!
node list.js
And just like that, your first file is now stored on IPFS!
Check all your files on Starton Web Application
Congratulations on uploading your first file on IPFS! In this tutorial, you discovered how to upload your first file on IPFS but this is only the first step.