- implement in python (use of any libraries and DB services is optional)
- upload, download, delete file
- list files available on file server (with filtering options)
- statistics of files available on file server
- uploaded file has following metadata:
- name
- extension type
- size
- upload datetime
- small files - max. 100 MiB, but most of the arround 1 MiB
- a lot of files
- used mainly via JS from web browser
- authentication and authorization is not needed
- more reading than writing
- solution is dockerized, so you need docker installed on your system
curl
for manual tests
Extract provided ZIP file.
cd PROJECT_FOLDER
docker build -t file-server .
docker run -p 5000:5000 file-server
Now you can play with file server in another terminal window, web browser, or elsewhere :).
Files are not persistent. Restarted docker service will start empty.
curl -X POST -F "file=@PATH_TO_YOUR_FILE" http://localhost:5000/file
- returns:
{
"file_info":
{
"datetime_uploaded": ISO DATETIME as STRING,
"name": STRING,
"size_bytes": INT,
"type": STRING
},
"message": STRING
}
Upload of new file with same name will overwrite the old one. Max upload size of one file is 100 MiB.
curl -o OUTPUT_FILE_NAME http://localhost:5000/file/TARGET_FILE_NAME
curl -X DELETE http://localhost:5000/file/TARGET_FILE_NAME
- returns:
{
"message": STRING
}
curl http://localhost:5000/file
- with type filtering
curl http://localhost:5000/file?type=.md
- with name ordering ascending
curl http://localhost:5000/file?sort_by_size=asc
- with name ordering descending
curl http://localhost:5000/file?sort_by_size=desc
- or you can combine it like this
curl "http://localhost:5000/file?type=.md&sort_by_size=asc"
- with type filtering
- returns:
{
"files":
[
{
"datetime_uploaded": ISO DATETIME as STRING,
"name": STRING,
"size_bytes": INT,
"type": STRING
}
]
}
curl http://localhost:5000/file/statistics
- return:
{
"avg_size_bytes": INT,
"median_size_bytes": INT,
"num_of_files": INT,
"total_size_bytes": INT
}
- how to handle file persistence
- README documents only happy path responses
- possible authorization / authentification
- how to not overwrite files with same name
- I deliberately avoided all comments - code is short and straightforward
- when possible - put all info into code, not into comments
- in production code I like to use google style docstrings - github example
- I do not follow PEP 8 line length
- usually I like to use limit around ~ 120 characters per line - but it is all about consensus in team
- integration of static type checking, linters and code formatter, I like to use following:
- mypy - github link
- ruff - github link