Recover interrupted uploads
These examples use the latest stable release of the Python SDK.
Before uploading, save the drive ID, an idempotency key and the ordered list of file paths. Keep the bytes, external IDs, metadata and folder unchanged for a retry. Unfinished upload sessions and request keys last 24 hours. Keep the receipts of accepted uploads so you can resume by upload ID.
Inspect partial failures
from flashdrive import Flashdrive, UploadBatchError, UploadError
with Flashdrive(drive_id="DRIVE_UUID") as client:
try:
batch = client.upload(
["handbook.pdf", "policies.md", "intro.mp4"],
idempotency_key="handbook-upload-1",
)
except UploadBatchError as exc:
for receipt in exc.batch.files:
print("Completed:", receipt.upload_id, receipt.document_id)
for file_key, issue in exc.failures.items():
print(file_key, str(issue))
if isinstance(issue, UploadError) and issue.receipt is not None:
receipt = issue.receipt
print("Recover with:", receipt.upload_id, receipt.drive_id)
print("Original request:", exc.idempotency_key, exc.drive_id)
UploadBatchError (code upload_batch_failed) is raised even when only one file was uploaded. exc.batch.files holds the receipts of the files that succeeded. exc.failures maps each failed file to its error; the key is the file's position and name, such as 0:handbook.pdf. A failed or timed-out entry that is an UploadError can carry a receipt for work the service already accepted. exc.idempotency_key and exc.drive_id are what a retry needs.
Choose the recovery action
| State | Action |
|---|---|
| Bytes have not finished transferring | Repeat the original upload with the same key, the complete ordered path list and unchanged inputs. |
| Processing is queued or running | Resume waiting by upload ID with uploads.resume(). |
Local waiting timed out (UploadTimeoutError, code upload_timeout) | Inspect the receipt and resume; a local timeout does not cancel accepted work. |
| The file or its inputs were refused, or processing failed | Correct the file or input, then start a new upload with a new key. |
| The session expired | Check the file with client.files.list() or client.documents.get() before starting a new upload. |
When you reuse a batch key, send the complete original file list in the same order. The SDK identifies each file by its position, so retrying a subset or changing the order changes those identities. To continue one upload the service has already accepted, use its receipt with uploads.resume().
Resume waiting
from flashdrive import Flashdrive, UploadTimeoutError
with Flashdrive() as client:
try:
ready = client.uploads.resume("UPLOAD_UUID", drive_id="DRIVE_UUID")
print(ready.status, ready.document_id)
except UploadTimeoutError as exc:
if exc.receipt is not None:
print("Still processing:", exc.receipt.upload_id, exc.receipt.drive_id)
uploads.resume(upload_id, *, drive_id, timeout=600) waits for an accepted upload and returns its UploadReceipt. Use the IDs from the saved receipt. If the file's bytes never finished transferring, it raises an UploadError with code upload_transfer_incomplete: repeat the original upload with its saved inputs and key to send them.
The SDK keeps upload state in memory only. To recover after your process restarts, save the original request inputs and the receipt IDs in your application's own job record, and keep credentials in your usual secret storage. See errors and retries.
Queued processing and the transfer deadline
Once a file's bytes are verified and queued for processing, it stays queued even after the 24-hour transfer deadline, and it counts toward your storage while it is processed. Follow it by its saved upload ID.
The original request key can be reused for 24 hours. Reusing an old batch key after that can create new uploads, so resume queued uploads by their saved IDs rather than repeating the batch.
Cancelling or timing out stops only your local waiting. Work the service already accepted continues.