Breakpoint resume is suitable for large file transfers or unstable network conditions. TOS iOS SDK splits the object into multiple parts and saves them to checkpoint. After a task is paused or interrupted abnormally, resuming the same request continues transferring from completed parts without retransmitting the entire file.
- Available Endpoint, Region, and Bucket must be prepared.
- Ensure the upload source file path, download target directory, and checkpoint directory are all accessible.
- The sample code uses Objective-C and can be placed in the project’s .m file.
Each transfer task must use a separate checkpoint path. The following example saves the checkpoint in the App's Application Support directory:
Downloaded data is first written to a temporary file. The SDK atomically replaces the target file only after all chunks are downloaded and verified successfully. Therefore, pausing or failing the transfer does not damage the existing target file.
Pause and resume download
When the user triggers a pause, call the following interface to pause the download task:
After the original task callback completes, recreate the request with the same parameters:
Calling TOSCancelHook immediately terminates the task and clears the resume state. If you call the related interface again after termination, the task will restart from the beginning.
Terminate the task using TOSCancelHook from each request:
Warning
Do not reuse an old TOSCancelHook after a task has succeeded or terminated.