
A customer loses their connection halfway through sending a video. The progress bar stops at 42%. How many bytes should the app skip when they reconnect? With the tus protocol, the upload has its own URL. A fresh client can ask that URL how many bytes the server has accepted, seek to that position in the original file, and send the rest.
We cut a connection in the middle of a request, restarted the upload server, and finished the file from a new Python process. The server had kept 262,144 bytes beyond the last acknowledged request. Reading its offset saved us from sending those bytes twice.
We used tusd 2.10.4, the reference tus server, with a local Moto S3 emulator. The client spoke tus to the server. Only the server needed bucket credentials. To try the same arrangement, create a disposable bucket, set BUCKET and S3_ENDPOINT, and provide the server with its access key, secret key and region. For this local test, the endpoint was on loopback and the credentials were dummy values. The tusd S3 backend guide lists the required permissions and configuration.
tusd -host 127.0.0.1 -port 1080 \
-s3-bucket "$BUCKET" -s3-endpoint "$S3_ENDPOINT" \
-s3-object-prefix uploads/
From another terminal, create an upload for a file named sample.bin. This example uses a POSIX shell. The empty request body creates the resource, and Upload-Length declares the total size in bytes.
curl -sS -D - -o /dev/null -X POST http://127.0.0.1:1080/files/ \
-H 'Tus-Resumable: 1.0.0' \
-H "Upload-Length: $(wc -c < sample.bin)" \
--data-binary ''
Look for 201 Created. Save the Location response header as UPLOAD_URL, resolving it against the request URL if it is relative. Keep that URL with the identity of the selected file so the app can find both after a page reload. A second POST creates a separate upload. Before resuming, make sure the user still has the same file. Two different videos can have exactly the same length.
Send HEAD to the saved URL. An Upload-Offset of 4096 means that bytes 0 through 4095 have arrived. Start reading at byte 4096. Send the next chunk in a PATCH with that offset and the content type application/offset+octet-stream. A successful response is 204 No Content with the new offset. These rules come from the tus resumable upload protocol.
Save the following as resume.py. It handles a new or partially completed upload of known length and reads up to 4 MiB into memory per request. It expects a single writer and a source file that stays unchanged.
import sys
from pathlib import Path
from urllib.request import Request, urlopen
file = Path(sys.argv[1])
url = sys.argv[2]
size = file.stat().st_size
headers = {"Tus-Resumable": "1.0.0"}
with urlopen(Request(url, method="HEAD", headers=headers), timeout=30) as reply:
offset = int(reply.headers["Upload-Offset"])
length = int(reply.headers["Upload-Length"])
if length != size or not 0 <= offset <= size:
raise ValueError("The upload length or offset does not match this file")
with file.open("rb") as source:
source.seek(offset)
while offset < size:
chunk = source.read(min(4 * 1024 * 1024, size - offset))
if not chunk:
raise IOError("The source file changed during transfer")
patch_headers = {**headers, "Upload-Offset": str(offset),
"Content-Type": "application/offset+octet-stream"}
req = Request(url, method="PATCH", data=chunk, headers=patch_headers)
with urlopen(req, timeout=60) as reply:
confirmed = int(reply.headers["Upload-Offset"])
if reply.status != 204 or confirmed != offset + len(chunk):
raise IOError("Unexpected server offset; check with HEAD")
offset = confirmed
print(offset)
python resume.py sample.bin "$UPLOAD_URL"
If the connection drops or a request times out, rerun the command with the same file and URL. It starts with another HEAD. A 409 Conflict means the proposed offset differs from the stored one. Check whether another client is writing before continuing. An expired upload can require a new URL.
Our test file contained 12,583,049 bytes. We sent an initial chunk, then opened a second request and closed the sending side of its socket before the declared body was complete. The S3 emulator stayed running throughout the test.
Another disconnect can leave a different number of bytes committed. A reader that reconstructs the offset from a progress bar or its own send counter would miss that distinction.
After completion, we downloaded the file through tusd and fetched the finished object independently with an S3 client. Both downloads matched the source byte for byte and had the same SHA-256 digest. The offset established completeness by length. Comparing the digest also checked the contents.
During an unfinished upload, tusd can keep a metadata object and a temporary part in the bucket. Have downstream jobs wait for completion before processing the file. The S3 multipart upload guide explains how the storage service assembles the final object.
To evaluate Object Storage with Hivenet for an upload service, repeat the disconnect, restart and independent download against a disposable bucket on your intended endpoint. For a browser-facing service, test through the actual HTTPS proxy with authentication on the upload routes. The local run verified recovery and integrity. Transfer speed and behavior under concurrent uploads need measurements on your deployment.
Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.