This project allows users to upload files to the InterPlanetary File System (IPFS). JSON web tokens (JWT) are supported for the add
and delete
endpoints. Unit tests are included for the REST layer; consult the section below for instructions.
- In the root folder, enter
docker-compose up
. This will run a Flask API container and an IPFS daemon container.
- Create a new python virtual environment.
- Enter the rest folder, and install environment with
pip install -r requirements.txt
. - Start the flask API layer with
python run.py
. - Start the IPFS daemon with
ipfs daemon
.
Postman JSON commands can be found at
IPFS Collections.postman_collection
in the main directory
// Register a new user, receive access token
curl -X POST \
http://0.0.0.0:8081/registration \
-H 'Content-Type: application/json' \
-d '{
"username": "bob",
"password": "hill"
}'
// Upload a file - Requires JWT access_token
curl -X POST \
http://0.0.0.0:8081/add \
-H 'Cache-Control: no-cache' \
-H 'content-type: multipart/form-data;
-H "Authorization: JWT <token here>"
-F fileObj=File to upload
// Delete a file - Requires JWT access_token
curl -X POST \
http://0.0.0.0:8081/delete \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H "Authorization: JWT <token here>"
-d '{
"file": "Content Base Address"
}'
There are unit tests for most endpoints in the rest
folder. Begin testing with python test.py
. Note that ipfs daemon
must be running to test the add
and delete
endpoints.
The REST api is created with flask
framework. the key files are:
app.py
- creates a flask app set up with REST endpoints
- includes an SQLite database based on the ORM model described in models
models.py
- creates an object relational model (ORM) for handling user information
- declares token black list model
resources.py
- stores the implementation details of each endpoint.
run.py
- main entry point for the app
You can ensure that a file has been uploaded correctly by running ipfs cat content_base__address > result.png
.