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.
This project relies on the tcp-over-udp implementation for file transfer. You can find the full implementation and details of the TCP-over-UDP protocol in the tcp-over-udp repository.
All endpoints are prefixed with /file-transfer
.
Example:
http://localhost:8080/file-transfer
To use Amazon S3 for file storage, set up a .env
file in the root of your project directory with the following environment variables:
# .env
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_REGION=your-aws-region
These environment variables are necessary for the application to authenticate with AWS and interact with your S3 bucket.
Note: The
.env
file is included in.gitignore
to keep credentials secure.
Uploads a file to an Amazon S3 bucket for storage.
- URL:
/file-transfer/upload
- Method:
POST
- Description: Uploads a file to a specified S3 bucket.
- file: (multipart/form-data) The file to be uploaded.
- bucketName: (string) The name of the S3 bucket where the file will be stored.
- fileName: (string) The name to save the file as in S3.
curl -X POST -F "file=@/path/to/your/file.txt" \
-F "bucketName=your-s3-bucket-name" \
-F "fileName=uploaded-file.txt" \
http://localhost:8080/file-transfer/upload
- Success: Returns a message with the S3 ETag confirming the file was uploaded successfully.
- Error: Returns a
500 Internal Server Error
if the upload fails.
Downloads a file from S3 and serves it as a downloadable resource.
- URL:
/file-transfer/download
- Method:
GET
- Description: Fetches a file from S3 based on the provided bucket and file name.
- bucketName: (query parameter) The name of the S3 bucket where the file is stored.
- fileName: (query parameter) The name of the file in S3.
curl -X GET "http://localhost:8080/file-transfer/download?bucketName=your-s3-bucket-name&fileName=your-file-name" -o downloaded-file.txt
- Success: Returns the file as a downloadable resource.
- Error: Returns a
404 Not Found
if the file does not exist or a500 Internal Server Error
if the download fails.
Uploads and sends a file to a specified receiver over a custom TCP-over-UDP protocol.
- URL:
/file-transfer/send
- Method:
POST
- Description: Uploads a file and sends it to a designated receiver.
- file: (multipart/form-data) The file to be sent.
- receiverHostname: (string) The hostname or IP address of the receiver.
- receiverPort: (integer) The port on which the receiver is listening.
- bytesToTransfer: (integer) The number of bytes to transfer.
curl -X POST -F "file=@/path/to/your/file.txt" \
-F "receiverHostname=localhost" \
-F "receiverPort=12345" \
-F "bytesToTransfer=1024" \
http://localhost:8080/file-transfer/send
- Success: Returns a message confirming that the file was sent successfully.
- Error: Returns a
500 Internal Server Error
with details if the transfer fails.
Initiates the receiver process to download a file over TCP-over-UDP, then serves it as a downloadable resource.
- URL:
/file-transfer/receive
- Method:
GET
- Description: Starts the receiver to download the file over the TCP-over-UDP protocol.
- filename: (query parameter) The name of the file to save the received data as.
- port: (query parameter) The port number for the
receiver
to listen on.
- fileStorageLocation: (string, required) The directory path where the received file should be stored temporarily.
curl -X GET "http://localhost:8080/file-transfer/receive?filename=received_file.txt&port=12345" \
-H "fileStorageLocation:/custom/downloads"
- Success: Serves the file as a downloadable resource.
- Error: Returns a
404 Not Found
if the file cannot be found or500 Internal Server Error
if the reception fails.
To run the backend locally, follow these steps:
- Java 17 (or compatible version for your Spring Boot setup)
- Gradle (or use the included Gradle Wrapper,
./gradlew
) - GCC (for compiling the TCP-over-UDP binaries)
-
Clone the Repository
git clone https://github.com/eomielan/file-sync.git cd file-sync/backend
-
Compile the TCP-over-UDP Binaries
cd tcpOverUdp make
-
Configure the .env File
Create a
.env
file in the backend root with your AWS credentials and region:AWS_ACCESS_KEY_ID=your-access-key-id AWS_SECRET_ACCESS_KEY=your-secret-access-key AWS_REGION=your-aws-region
-
Run the Backend
cd .. ./gradlew bootRun
-
Test the Endpoints
You can now test the
/file-transfer/send
,/file-transfer/receive
,/file-transfer/upload
, and/file-transfer/download
endpoints usingcurl
or Postman.
-
Navigate to the Backend Directory
cd file-sync/backend
-
Run All Tests
./gradlew test
-
View Test Results
Test results are available in
build/reports/tests/test/index.html
. -
Run Specific Tests
./gradlew test --tests "com.networking.filetransfer.controller.FileControllerTest"