This script uploads a directory structure to the Bee network using Mantaray as a manifest node. It lists files, saves a manifest, and allows downloading files.
- Node.js: Ensure you have Node.js installed.
- Bee Node: Download and install the Bee node binary.
- Swarm CLI: Install the Swarm CLI tool.
- Postage Stamp: Use
swarm-cli
to buy a postage stamp for uploading files to the Bee network.
Start the Bee node with the --dev
flag to enable developer mode:
bee dev --cors-allowed-origins="*"
Clone this repository and navigate to the directory:
git clone https://github.com/Solar-Punk-Ltd/mantaray-file-manager
cd mantaray-file-manager
npm install -g @ethersphere/swarm-cli
Check if you have any active postage stamps:
swarm-cli stamp list
If no stamps exist or you want to purchase a new one, run the following command:
swarm-cli stamp buy --amount 100000000000 --depth 20
Example Output:
Batch ID: c0598ec076f1a7222b9f074343c1009535e045cfa70e50aa34ca5c6b868a4daf
Replace batch id in the index.ts:
const STAMP = 'your-postage-stamp-id';
Run the script to upload the directory, generate a Mantaray manifest, list the files, and download the uploaded files:
npm run build
npm start
- Error: You are unable to access files using the manifest reference URL.
- Solution: Ensure that:
- The manifest reference is correctly copied from the console output.
- The Bee node is running and accessible at
http://localhost:1633
.
- Error: Specific files are not accessible even though the manifest reference is valid.
- Solution: Verify that:
- The directory structure (
nested-dir
) is correct and includes the expected files. - The files were properly uploaded and listed during the script's execution.
- The directory structure (
- Error: Uploads fail due to insufficient funds or expired postage stamps.
- Solution:
- Purchase a new postage stamp using:
curl -s -X POST http://localhost:1635/stamps/1000000/20
- Update the
STAMP
constant in the script with the new postage stamp ID.
- Purchase a new postage stamp using:
- Error: Files or directories in
nested-dir
cannot be read. - Solution:
- Ensure all files have read permissions:
chmod -R 755 nested-dir
- Ensure all files have read permissions:
- Error: The Bee node stops unexpectedly during the upload or download process.
- Solution:
- Restart the Bee node:
bee dev --cors-allowed-origins="*"
- Check the Bee node logs for errors and address any issues.
- Restart the Bee node:
You can enhance the script by:
-
Adding Metadata:
- Include additional metadata (e.g., timestamps or user-defined tags) for each file during the upload process.
-
Dynamic Directory Selection:
- Allow users to dynamically select the directory to upload by adding a prompt or configuration setting.
-
Batch Processing:
- Handle larger directories by implementing batch processing to upload files in chunks.
-
UI Integration:
- Create a simple frontend interface to upload, list, and download files directly from the browser.
-
Swarm Dashboard:
- Use a dashboard to monitor the Bee node's status, uploaded content, and active postage stamps.
-
Postage Stamp Management:
- Build or integrate tools to manage and renew postage stamps efficiently.
Happy Swarming! 🐝