An application that exposes an API accepting and serving files.
- Go installed on your machine (v1.21)
- Docker and Docker Compose for running Minio locally
-
Clone the repository:
git clone https://github.com/huangrpablo/file-server-go.git cd file-server-go
-
Start Minio using Docker Compose:
docker-compose up -d
Minio will be available at http://127.0.0.1:9000 with default credentials minioadmin:minioadmin
.
-
Make a bucket in Minio for file storage. The default bucket is
taurus-file-store
, which can be configured inconfig/config.yaml
. -
Build and run the File Server App:
go run main.go
The File Server App should now be running at http://127.0.0.1:8080.
- Endpoint:
POST /v1/files
- Request:
curl -X POST -F "file=@/path/to/your/file.txt" http://127.0.0.1:8080/v1/files
- Response:
{"message":"File uploaded successfully"}
- Endpoint:
GET /v1/file/{fileName}
- Request:
curl http://127.0.0.1:8080/v1/file/{fileName} -o myfile
- Response:
File contents streamed to the
myfile
The configuration can be made in config/config.yaml
.
app.chunkSize
: the chunkSize for multipart uploading to minio (default: 5242880)app.uploadInChunk
: whether a file will be uploaded in parts to minio (default: false)app.bucketName
: the bucket where files are stored in minio (default: taurus-file-store)
-
Filename as a unique file id
- For simplicity, filename of the uploaded file is chosen as the object key in minio, which is decided by the user. Two files with the same name will overwrite the object in the bucket. But as the versioning can be enabled, the overwritten file can still be retrieved (not implemented via API yet). The download of the file also uses the filename.
- However, it is also an option to let the server generate a unique file id as the object key, and return the id in the HTTP response. The user uses the returned id to access and manipulate the resource (an API for file modification needs to be implemented).
-
Upload in chunks done by Minio API
- Minio supports multipart upload by specifying
PartSize
(controlled viachunkSize
inconfig/config.yaml
). - However, the minimum chunk size is 5MB, while in the instruction, 1MB should be possible.
- To achieve this, the chunking can be implemented by the server itself (not implemented yet).
- Minio supports multipart upload by specifying
-
Input validation done by gin binding
-
Simple AES encryption (can be improved by using more custom and complex encryption strategy).
-
The implementation of AES is taken from Secret Key Encryption.
- Build the file server app into a docker image
- Find out why minio actions are so slow: for a 500MB file, it takes 4 ~ 9 seconds to upload (it could be the limited resources allocated)
- Write more unit tests, some with dependency injection
- More things can be configured, such as the cryptography algorithm