upload-to-ipfs
v0.2.0
Published
CLI to upload a folder to IPFS using IPFS RPC API
Downloads
124
Maintainers
Readme
upload-to-ipfs
CLI to upload files or folders to IPFS using IPFS RPC API.
Installation
npm install upload-to-ipfsOr build from source:
pnpm install
pnpm buildUsage
CLI Usage
upload-to-ipfs <directory-path> [options]Options
--output <file>- Output file for result (default: print CID to stdout)--rpc-url <url>- IPFS RPC URL (default:IPFS_RPC_URLenv var)--api-key <key>- API key for Authorization header (default:IPFS_API_KEYenv var)--pin- Pin the uploaded files
Environment Variables
IPFS_RPC_URL- IPFS RPC URL (required if not provided via--rpc-url)IPFS_API_KEY- API key for Authorization header (optional)
Examples
Upload a single file:
upload-to-ipfs test-data/hello.txt --rpc-url http://127.0.0.1:5001Upload a directory:
# Using environment variables
export IPFS_RPC_URL=http://127.0.0.1:5001
upload-to-ipfs test-data
# Using command-line arguments
upload-to-ipfs test-data --rpc-url http://127.0.0.1:5001
# Upload with pinning
upload-to-ipfs test-data --rpc-url http://127.0.0.1:5001 --pin
# Upload with output file
upload-to-ipfs test-data --rpc-url http://127.0.0.1:5001 --output result.jsonProgrammatic Usage
import { upload, UploadParams } from 'upload-to-ipfs';
const params: UploadParams = {
rpcUrl: 'http://127.0.0.1:5001',
apiKey: 'your-api-key', // optional
pin: true, // optional
outputFile: 'result.json' // optional
};
await upload('./my-folder', params);Development
Build
pnpm buildTest with test-data
# Start a local IPFS node first
ipfs daemon
# Then run the upload
./dist/cli.cjs test-data --rpc-url http://127.0.0.1:5001License
MIT
