This repository demonstrates an implementation of the TUS protocol for resumable file uploads. The TUS protocol is a standard for resumable uploads, allowing clients to upload files to a server in a fault-tolerant and efficient manner. It supports pausing, resuming, and retrying uploads, making it ideal for large file transfers.
- client/: Contains the client-side implementation for uploading files using the TUS protocol.
- server/: Contains the server-side implementation for handling TUS uploads and processing files.
- Node.js (v16 or later)
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/Kodifly/tus-implementation.git cd tus-implementation -
Install dependencies for the client:
cd client npm install -
Install dependencies for the server:
cd ../server npm install
-
Configure the
.envfile in theclient/directory:FOLDER_PATH=/path/to/your/folder HOST=localhost PORT=8000 -
Start the client:
cd client npm start -
The client will upload all the files present in the
FOLDER_PATHenvironment variable to the server.
-
Configure the
.envfile in theserver/directory:HOST=localhost PORT=8000 UPLOAD_PATH=../uploads PROCESSED_PATH=../processed API_TOKEN=your-api-token -
Start the server:
cd server npm start -
The server will listen for incoming TUS uploads and process them.
- Description: Creates a new upload session.
- Headers:
Upload-Length: Total size of the file in bytesUpload-Metadata: Metadata about the file (e.g., filename)
- Response:
201 Created: Returns the upload URL in theLocationheader.
- Description: Processes uploaded videos.
- Body:
{ "api_token": "your-api-token", "file_uuids": ["uuid1", "uuid2"] } - Using CURL
curl -X POST http://10.12.12.13:8000/api/videos/api-token-segmentation \ -H "Content-Type: application/json" \ -d '{ "api_token": "your-api-token", "file_uuids": ["uuid1","uuid2"] }'
- Note: Replace
10.12.12.13and8000with the actual server IP and Port number. - Response:
200 OK: Returns the task ID for the processing job.
- Start the server.
- Use the client to upload a file.
- Use CURL to call the
/api/videos/api-token-segmentationto process the uploaded file. - Download the processed file using
/api/download/{file_uuid}.