The following sample code shows how to upload an object body with the resumable transfer.
Here is what is happening in the sample code:
- Set key-value pairs (e.g., file name, file size, and the availability of an object body) in a KiiObject as needed.
- Create a reference to the target file (sample.mp4).
- Create a
KiiUploader instance by calling the
uploader(_:) method with the target file reference.
- Define a progress block.
- Start uploading by calling the
If the KiiObject has an object body, uploading a new file will replace the existing object body.
For a resumable upload, the
save(_:) method is automatically executed in case the method is not executed prior to calling the
Note that the progress block will not be called if you execute the blocking
transfer(progressBlock:_:) method from the main thread.
The progress block will be called as the upload progresses. The block can reach 100% on the first call if the data size is small.
If the upload is interrupted for some reasons, it will be suspended, and an error will be thrown. In this case, you can resume the upload (For the steps to resume, see Resuming an Upload).