Skip to content

Commit b313b86

Browse files
committed
Update README
1 parent 8c84534 commit b313b86

File tree

1 file changed

+91
-54
lines changed

1 file changed

+91
-54
lines changed

backend/README.md

Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File Sync Backend
22

3-
This project provides backend APIs for transferring files using a custom TCP-over-UDP protocol. It includes endpoints for sending and receiving files, allowing you to specify the file storage location dynamically in each request.
3+
This project provides backend APIs for transferring files using a custom TCP-over-UDP protocol and S3 for file storage. It includes endpoints for sending, receiving, uploading, and downloading files.
44

55
## Related Repository
66

@@ -16,15 +16,86 @@ Example:
1616
http://localhost:8080/file-transfer
1717
```
1818

19+
## Environment Configuration
20+
21+
To use Amazon S3 for file storage, set up a `.env` file in the root of your project directory with the following environment variables:
22+
23+
```plaintext
24+
# .env
25+
AWS_ACCESS_KEY_ID=your-access-key-id
26+
AWS_SECRET_ACCESS_KEY=your-secret-access-key
27+
AWS_REGION=your-aws-region
28+
```
29+
30+
These environment variables are necessary for the application to authenticate with AWS and interact with your S3 bucket.
31+
32+
> **Note:** Ensure that the `.env` file is included in `.gitignore` to keep your credentials secure.
33+
1934
## Endpoints
2035

21-
### 1. Upload and Send File
36+
### 1. Upload File to S3
2237

23-
Upload a file and send it to a specified receiver.
38+
Uploads a file to an Amazon S3 bucket for storage.
39+
40+
- **URL**: `/file-transfer/upload`
41+
- **Method**: `POST`
42+
- **Description**: Uploads a file to a specified S3 bucket.
43+
44+
#### Request Parameters
45+
46+
- **file**: (multipart/form-data) The file to be uploaded.
47+
- **bucketName**: (string) The name of the S3 bucket where the file will be stored.
48+
- **fileName**: (string) The name to save the file as in S3.
49+
50+
#### Example `curl` Request
51+
52+
```bash
53+
curl -X POST -F "file=@/path/to/your/file.txt" \
54+
-F "bucketName=your-s3-bucket-name" \
55+
-F "fileName=uploaded-file.txt" \
56+
http://localhost:8080/file-transfer/upload
57+
```
58+
59+
#### Response
60+
61+
- **Success**: Returns a message with the S3 ETag confirming the file was uploaded successfully.
62+
- **Error**: Returns a `500 Internal Server Error` if the upload fails.
63+
64+
---
65+
66+
### 2. Download File from S3
67+
68+
Downloads a file from S3 and serves it as a downloadable resource.
69+
70+
- **URL**: `/file-transfer/download`
71+
- **Method**: `GET`
72+
- **Description**: Fetches a file from S3 based on the provided bucket and file name.
73+
74+
#### Request Parameters
75+
76+
- **bucketName**: (query parameter) The name of the S3 bucket where the file is stored.
77+
- **fileName**: (query parameter) The name of the file in S3.
78+
79+
#### Example `curl` Request
80+
81+
```bash
82+
curl -X GET "http://localhost:8080/file-transfer/download?bucketName=your-s3-bucket-name&fileName=your-file-name" -o downloaded-file.txt
83+
```
84+
85+
#### Response
86+
87+
- **Success**: Returns the file as a downloadable resource.
88+
- **Error**: Returns a `404 Not Found` if the file does not exist or a `500 Internal Server Error` if the download fails.
89+
90+
---
91+
92+
### 3. Send File via TCP-over-UDP
93+
94+
Uploads and sends a file to a specified receiver over a custom TCP-over-UDP protocol.
2495

2596
- **URL**: `/file-transfer/send`
2697
- **Method**: `POST`
27-
- **Description**: Uploads a file to the backend and sends it to the specified receiver over a custom TCP-over-UDP protocol.
98+
- **Description**: Uploads a file and sends it to a designated receiver.
2899

29100
#### Request Parameters
30101

@@ -50,13 +121,13 @@ curl -X POST -F "file=@/path/to/your/file.txt" \
50121

51122
---
52123

53-
### 2. Receive and Download File
124+
### 4. Receive File via TCP-over-UDP
54125

55-
Trigger the receiver to download a file over TCP-over-UDP, then serve it as a downloadable resource.
126+
Initiates the receiver process to download a file over TCP-over-UDP, then serves it as a downloadable resource.
56127

57128
- **URL**: `/file-transfer/receive`
58129
- **Method**: `GET`
59-
- **Description**: Initiates the file reception via the custom TCP-over-UDP protocol and provides the file for download.
130+
- **Description**: Starts the receiver to download the file over the TCP-over-UDP protocol.
60131

61132
#### Request Parameters
62133

@@ -95,95 +166,61 @@ To run the backend locally, follow these steps:
95166

96167
1. **Clone the Repository**
97168

98-
Clone the repository to your local machine:
99-
100169
```bash
101170
git clone https://github.com/eomielan/file-sync.git
102171
cd file-sync/backend
103172
```
104173

105174
2. **Compile the TCP-over-UDP Binaries**
106175

107-
The backend requires the `sender` and `receiver` binaries from the [tcp-over-udp repository](https://github.com/eomielan/tcp-over-udp). Compile these binaries by running `make` in the `src/tcpOverUdp` directory:
108-
109176
```bash
110177
cd tcpOverUdp
111178
make
112179
```
113180

114-
- This will generate the `sender` and `receiver` executables required for file transfer.
115-
- Ensure both binaries are executable (if not, use `chmod +x sender receiver`).
116-
117-
3. **Configure Application Properties**
181+
3. **Configure the .env File**
118182

119-
Open `src/main/resources/application.properties` to configure any necessary properties, such as server port (optional):
183+
Create a `.env` file in the project root with your AWS credentials and region:
120184

121-
```properties
122-
# Default server port (optional)
123-
server.port=8080
185+
```plaintext
186+
AWS_ACCESS_KEY_ID=your-access-key-id
187+
AWS_SECRET_ACCESS_KEY=your-secret-access-key
188+
AWS_REGION=your-aws-region
124189
```
125190

126191
4. **Run the Backend**
127192

128-
Start the Spring Boot backend using the Gradle Wrapper:
129-
130193
```bash
131-
cd .. # Navigate back to the project root
194+
cd ..
132195
./gradlew bootRun
133196
```
134197

135-
Alternatively, if you have Gradle installed, you can also use:
136-
137-
```bash
138-
gradle bootRun
139-
```
140-
141-
This command will start the backend server on `http://localhost:8080` (or on the port specified in `application.properties`).
142-
143198
5. **Test the Endpoints**
144199

145-
You can now test the `/file-transfer/send` and `/file-transfer/receive` endpoints using `curl` or Postman. Ensure that the receiver is set up and listening on the specified port when testing the `send` endpoint.
200+
You can now test the `/file-transfer/send`, `/file-transfer/receive`, `/file-transfer/upload`, and `/file-transfer/download` endpoints using `curl` or Postman.
146201

147202
---
148203

149204
## How to Run Tests
150205

151-
The backend includes unit and integration tests for verifying file transfer functionality, error handling, and endpoint responses. These tests are implemented using **JUnit 5** and **Mockito**.
152-
153-
### Running Tests with Gradle
154-
155206
1. **Navigate to the Backend Directory**
156207

157-
Make sure you’re in the `backend` directory:
158-
159208
```bash
160209
cd file-sync/backend
161210
```
162211

163212
2. **Run All Tests**
164213

165-
To run all tests, use the following Gradle command:
166-
167214
```bash
168215
./gradlew test
169216
```
170217

171-
Alternatively, if Gradle is installed, you can use:
172-
173-
```bash
174-
gradle test
175-
```
176-
177218
3. **View Test Results**
178219

179-
Test results will be available in the `build/reports/tests/test/index.html` file. Open this file in a browser to view a detailed test report.
180-
181-
### Running Tests for a Specific Class
182-
183-
If you want to run tests for a specific class, use the following command:
220+
Test results are available in `build/reports/tests/test/index.html`.
184221

185-
```bash
186-
./gradlew test --tests "com.networking.filetransfer.controller.FileControllerTest"
187-
```
222+
4. **Run Specific Tests**
188223

189-
Replace `FileControllerTest` with the specific test class name.
224+
```bash
225+
./gradlew test --tests "com.networking.filetransfer.controller.FileControllerTest"
226+
```

0 commit comments

Comments
 (0)