From 422e73b98d84d925692bc4d8fa7b1d4a80a657a3 Mon Sep 17 00:00:00 2001 From: rahuld109 Date: Thu, 26 Sep 2024 23:35:46 +0530 Subject: [PATCH] chore: added readme --- .gitignore | 3 ++- Makefile | 3 +++ README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 0902b2f..08a55ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env tmp/ -.vscode \ No newline at end of file +.vscode +bin \ No newline at end of file diff --git a/Makefile b/Makefile index 7630c3f..77b3fc2 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ dev: air +build: + go build -o bin/service . + docker.chi.build: docker build -t chi . diff --git a/README.md b/README.md new file mode 100644 index 0000000..9096332 --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +## README for Backend Service + +This repository provides a Go backend service for initiating multipart uploads, generating presigned URLs for part uploads, and completing multipart uploads to Amazon S3. + +**Features:** + +- Implements a multi-part upload workflow for large files. +- Provides API endpoints for initiating, pre-signing individual parts, and completing uploads. +- Uses AWS S3 for storage. + +**Requirements:** + +- Go 1.17 or later +- AWS account with S3 bucket + +**Installation:** + +1. Clone this repository. +2. Create a `.env` file in the project root directory with the following environment variables: + - `AWS_ACCESS_KEY_ID`: The access id with s3 permissions. + - `AWS_SECRET_ACCESS_KEY`: The secret access key with s3 permissions. + - `AWS_REGION`: The AWS region where your S3 bucket is located. + - `AWS_BUCKET`: The name of your S3 bucket. + - `PORT`: Server running port + +**Running the Service:** + +1. Build the service: + ```bash + make build + ``` +2. Run the service: + ```bash + ./bin/service + ``` + +This will start the service and listen for requests on port 8080. + +**API Endpoints:** + +- **`/initiate` (GET):** Initiates a multipart upload for a file. + + - Query parameter: `key` (string): The name of the file to upload. + - Response: JSON object containing the `uploadId` for the multipart upload. + +- **`/presigned` (GET):** Generates a presigned URL for uploading a specific part of a multipart upload. + + - Query parameters: + - `key` (string): The name of the file to upload. + - `uploadId` (string): The `uploadId` obtained from the `/initiate` endpoint. + - `partNumber` (int): The part number of the part to upload. + - Response: JSON object containing the `uploadUrl` for the part upload, the `uploadId`, the `partNumber`, and the `expiresAt` timestamp for the presigned URL. + +- **`/complete` (POST):** Completes a multipart upload by providing the ETags of all uploaded parts. + - Request body: JSON object with a `parts` array containing objects with `PartNumber` (int) and `ETag` (string) keys for each uploaded part. + - Query parameters: + - `key` (string): The name of the file that was uploaded. + - `uploadId` (string): The `uploadId` obtained from the `/initiate` endpoint. + - Response: Status code 200 if the upload is completed successfully. + +**CORS Configuration:** + +The service is configured with CORS (Cross-Origin Resource Sharing) to allow requests from any origin. This configuration might need to be adjusted depending on your specific deployment environment. + +**Security Considerations:** + +- This example uses environment variables for sensitive information like AWS credentials. Consider using a more secure method for storing and managing secrets in production environments. +- The CORS configuration allows requests from any origin. This configuration should be tightened for production environments. + +**Contributing:** + +We welcome contributions to this project! Please see the CONTRIBUTING.md file for guidelines on how to contribute. + +**License:** + +This project is licensed under the MIT License. See the LICENSE file for details.