0.3.1 • Published 4 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-ipfs
or
yarn add luna-ipfs
or similar for pnpm
, bun
, etc.
Usage
Import and Initialize
import IPFSUploader from "luna-ipfs";
const uploader = new IPFSUploader();
await uploader.init(); // Initialize Luna
Uses 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 i
Build
npm run build
Test Dev mode
Update file and folder path on test file before proceeding:
npm run test:dev
Maintainer
make release level=patch
with debug
make release level=patch DEBUG=true
⚠️ Under Development ⚠️