Introduction
Welcome to the TUSKit documentation! TUSKit is a lightweight iOS SDK that provides an easy-to-use implementation of the TUS protocol, allowing you to easily upload and download files to and from a TUS server.
Installation
How to Install with CocoaPods
- Open your project in Xcode.
- If you haven’t set up CocoaPods yet, open Terminal and navigate to your project directory. Run the command:
$ pod init
- Edit the
Podfile
and add the following line:
pod 'TUSKit'
- Save the
Podfile
and run the command:
$ pod install
How to Install Manually
- Download the latest TUSKit framework from GitHub.
- Drag and drop the TUSKit framework into your Xcode project.
- In your project settings, navigate to the General tab and scroll down to the Frameworks, Libraries, and Embedded Content section.
- Click on the + button and select the TUSKit framework.
- Make sure the framework is added under Frameworks, Libraries, and Embedded Content and not Linked Frameworks and Libraries.
Usage
Importing TUSKit
In your Swift file, import the TUSKit module:
import TUSKit
Creating a TUSManager
To use TUSKit, create an instance of the TUSManager class:
let tusManager = TUSManager.shared
Uploading a File
To upload a file to the TUS server, use the uploadFile(_:)
method:
tusManager.uploadFile(fileURL) { progress, error in
// Handle progress and error
}
Downloading a File
To download a file from the TUS server, use the downloadFile(_:)
method:
tusManager.downloadFile(fileURL) { progress, error in
// Handle progress and error
}
Advanced Options
Setting Custom Headers
You can set custom headers to be sent along with the TUS requests. Use the setRequestHeader(_:forKey:)
method to add custom headers:
tusManager.setRequestHeader("Bearer token", forKey: "Authorization")
Setting Chunk Size for Upload
If you want to customize the chunk size for uploads, use the setUploadChunkSize(_:)
method:
tusManager.setUploadChunkSize(1024 * 1024) // 1MB
Override Default TUS Endpoint URL
If you have a custom TUS server endpoint, you can override the default endpoint URL using the overrideDefaultTUSUploadURL(_:)
method:
tusManager.overrideDefaultTUSUploadURL("https://custom-tus-server.com/files")
Conclusion
Congratulations! You now have a basic understanding of how to use TUSKit to upload and download files using the TUS protocol. For more detailed information and additional features, refer to the TUSKit documentation on GitHub.