This project is a simple Go server that implements file storage using a REST API. It allows you to store, retrieve, and delete files using HTTP requests. The server uses basic authentication for security and stores file metadata in an SQLite database.
- REST API: Supports PUT, GET, and DELETE requests to manage files.
- Basic Authentication: Secures requests using a password from the environment variable
SERVER_PASSWORD
. - File Storage: Stores files in a directory specified by the
STORAGE_FOLDER
environment variable. - Metadata Storage: Uses an SQLite database to store file metadata, including filename and content type.
- Configurable Port: Listens on port 8080 by default, configurable via the
SERVER_PORT
environment variable.
-
GET /: Accessing the server without specifying a bucket will display a summary of all buckets and the storage space used.
-
PUT /bucket/{bucketname}/{filename}: Store a file. Creates the bucket if it doesn't exist.
-
GET /bucket/{bucketname}/{filename}: Retrieve a file.
-
HEAD /bucket/{bucketname}/{filename}: Check if a file exists without retrieving it.
-
DELETE /bucket/{bucketname}/{filename}: Delete a file.
SERVER_PASSWORD
: Password for basic authentication.STORAGE_FOLDER
: Directory to store files (default:data/
).SERVER_PORT
: Port for the server to listen on (default:8080
).
To run this server using Docker, you can build a Docker image and run a container. Here are the steps:
-
Build the Docker Image:
docker build -t file-storage-server .
-
Run the Docker Container:
docker run -d -p 8080:8080 -e SERVER_PASSWORD=yourpassword -e STORAGE_FOLDER=/data -v /path/to/data:/data file-storage-server
To set up this server on a Synology NAS using Docker:
- Install Docker: Ensure Docker is installed on your Synology NAS.
- Open Docker: Launch the Docker application from the main menu.
- Create a New Container:
- Go to the "Registry" tab and search for your Docker image or build it locally.
- Go to the "Image" tab, select your image, and click "Launch".
- Configure the container settings:
- Set the environment variables
SERVER_PASSWORD
andSTORAGE_FOLDER
. - Map the container port 8080 to a local port.
- Mount a local directory to
/data
in the container.
- Set the environment variables
- Start the Container: Click "Apply" to start the container.
This project is licensed under the MIT License.