0.3.1 • Published 8 months ago
luna-ipfs v0.3.1
Luna ☾
A TypeScript SDK for uploading files & directories to IPFS using Helia.
Features
- File Upload
- ✅ NodeJs (Backend)
- ✅ Browser (React, NextJs, etc.)
- ✅ Pinning via remote URL
- Folder Upload
- ✅ NodeJs (Backend)
- ✅ Pinning via remote URL
- Fetch File
- ✅ NodeJs (Backend)
- ✅ Browser (React, NextJs, etc.)
Install
npm i luna-ipfsor
yarn add luna-ipfsor similar for pnpm, bun, etc.
Usage
Import and Initialize
import IPFSUploader from "luna-ipfs";
const uploader = new IPFSUploader();
await uploader.init(); // Initialize LunaUses default storage path "./ipfs-blocks" in /var/folders
Upload a File
Node.js
const fileCid = await uploader.uploadFile("./example.txt");
console.log("File uploaded to IPFS:", fileCid);Browser
const fileInput = document.querySelector("input[type='file']");
fileInput.addEventListener("change", async (event) => {
const file = event.target.files[0];
const fileCid = await uploader.uploadFile(file);
console.log("File uploaded to IPFS:", fileCid);
});Upload a Directory (Node.js only)
const folderCid = await uploader.uploadDirectory("./my-folder");
console.log("Folder uploaded to IPFS:", folderCid);Fetch a File from IPFS
const fileContent = await uploader.fetchFile("<CID>");
console.log("Fetched file content:", fileContent);Stop Helia
Helia instance should be stopped when done using:
await uploader.stop();This will also cleanup the temp folder used. But your files are permanently saved in IPFS.
💡 Check for available public gateways.
Dev
npm iBuild
npm run buildTest Dev mode
Update file and folder path on test file before proceeding:
npm run test:devMaintainer
make release level=patchwith debug
make release level=patch DEBUG=true⚠️ Under Development ⚠️