- upload file
- retrieve file by name
- delete file by name
- if multiple files have similar contents, reuse the contents
- authentication api with Basic Authen
- signature in http header to make secure data in transport
- check file type in white-list
- check size limit
- multiple files have similar contents, reuse the contents
I will use database for save real name of file, file content will be save on disk and rename with its content after md5
==> reuse contents decreases disk use for save data file
Example
Database
|------------|---------------|
| name | hash_content |
|------------|---------------|
|a.png | abcdd |
|b.png | abcdd |
|c.pgn | adssadds |
|------------|---------------|
file on disk will be rename build hash content file
abcdd
adssadds
- Authen Basic
==> Authen API
authen_basic = base64.b64encode(username + ":" + passwd).decode("ascii")
headers = {
'authenticate': 'Basic ' + authen_basic,
}
- make secure data in transport
Client will generate sign and put it in header , after that server recive data will be generate sign and recheck with header client send to
==> make secure data in transport
SECRET_KEY = "sdfsfFKLJodsg082343223_"
sign = hash_md5(str(md5_content_file + SECRET_KEY))
headers = {
'authenticate': 'Basic ' + str(generator_authen_basic()),
'sign-client': sign)
}
- Check file type in white-list
FILE_TYPE_ALLOW = {
"png": "image/png",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"pdf": "application/pdf",
"txt": "text/plain",
"csv": "text/plain",
"abc": "application/octet-stream"
}
- Check file size limit
FILE_SIZE = 1024*1024 # 1 MB
GET FILE
- end point:
http://xxx/api/v1/file/<filename>
- method: GET
- authentication: header
UPLOAD FILE
- end point:
http://xxx/api/v1/file/
- method: POST
- authentication: header
UPDATE FILE
- end point:
http://xxx/api/v1/file/<filename>
- method: PUT
- authentication: header
DELETE FILE
- end point:
http://xxx/api/v1/file/<filename>
- method: DELETE
- authentication: header
- install manual with CentOS 6/7
- install manual with NixOs
- install by Dockerfile
- install by docker-compose