Upload a Directory

It is possible to use Bee to upload whole directory structures at once.


If an uploaded directory contain an index.html file. When you navigate to the directory in a web browser, it will automatically be served to users from our Swarm gateways as if it were a website hosted by a normal web server! You can use this feature to host unstoppable websites in Swarm.

This feature makes use of the tar command line utility to package the directory into a single file that can then uploaded to the Bee API for processing and distributed into the swarm for later retrieval.


G-zip compression is not supported the current version of Bee, so make sure not to use the -z flag when using the tar command!

Upload the Directory Containing Your Website

First, use the tar command line utility to create an archive containing all the files of your directory. If uploading a website, we must take care to ensure that the index.html file is at the root of the directory tree.

tree build
โ”œโ”€โ”€ assets
โ”‚ย ย  โ””โ”€โ”€ style.css
โ”œโ”€โ”€ index.html
โ””โ”€โ”€ error.html

Now, we cd into the directory and bundle the whole directory as a tar file. This strategy ensures that the tar package maintains the correct directory structure. You may also pass an absolute path instead of ../my_website.tar

cd my_website
tar -cf ../my_website.tar *

Next, simply POST the tar file as binary data to Bee's dir endpoint, taking care to include the header Content Type: application/x-tar.

curl \
-H "Content-Type: application/x-tar" \
-H "Swarm-Index-Document: index.html" \
-H "Swarm-Error-Document: error.html"
--data-binary @my_website.tar http://localhost:1633/dirs

For instances where a Single Page App has a javascript router which handles url queries itself, simple pass index.html as the error document, and Bee will pass over control to the javascript served by the index.html file in the circumstance that a path does not yield a file from the manifest.

When the upload is successful, Bee will return a json document containing the Swarm Reference.


Now, simply navigate your browser to view the reference using the bzz endpoint and your website will be served!


Other files are served at their relative paths, e.g.


Once your data has been fully processed into the network, you will then be able to retrieve it from any Bee node.


If you are not able to download your file from a different Bee node, you may be experiencing connection issues, see troubleshooting connectivity for assistance.