This README provides a step-by-step guide on how to use the u2s-sdk to perform a resumable file upload using Python. The u2s-sdk is a library that helps you easily upload large files to the Up2Share platform with resumable uploads.
Before you get started, ensure you have the following:
- Python (3.6 or later) installed on your system.
- Your Up2Share API key (or OAuth token), which you can obtain from your Up2Share account.
-
Install the required dependencies:
pip install u2s-sdk
-
Include the
u2s-sdkin your project:from u2s_sdk.handler import ResumableUploadHandler from u2s_sdk.client import ApiClient
-
Create an Up2Share
ApiClientinstance by providing your API key and the base URL:api_key = 'your_api_key' api_client = ApiClient('https://api.up2sha.re', api_key=api_key, timeout=60)
-
Initialize the
ResumableUploadHandlerusing theApiClient:handler = ResumableUploadHandler(api_client)
-
Specify the file you want to upload, the chunk size, and open the file:
file_name = 'your_file.mp4' file_path = 'path/to/your/file/your_file.mp4' chunk_size = 1048576 # 1 MB with open(file_path, 'rb') as file: handler.simulate_chunk_upload(file, chunk_size, filename=file_name)
-
Save and run your Python script.
With this setup, your Python script will upload the specified file to Up2Share using resumable uploads with the given chunk size. The simulate_chunk_upload method automatically takes care of splitting and uploading the file in chunks.
If any issues occur during the upload process, the ResumableUploadHandler class handles exceptions and reports errors in the log.
First, make sure you have installed the required dependencies:
pip install -r requirements-dev.txtThen, run the tests:
pytestcd docs
make htmlpip install -e .