Resumable download
Overview
BOS enables downloading from a specific position within an object, allowing you to break a large object download into multiple sessions. If the download is interrupted, you can resume it from where it left off when restarting.
Similar to simple upload, read permissions for the object are required. Resumable uploads are supported by setting the Range parameter, which is ideal for handling large objects. For the definition of Range, refer to the HTTP RFC. If the Range parameter is included in the request header, the response will show the total file length and the returned range. Example: Content-Range: bytes 0-9/44, indicating a total file length of 44 and a returned range of 0-9.
Note:
- Attempting to read a 0-byte object with the Range parameter will result in a 400 error. The Range represents a closed interval at both ends.
- Objects stored in the archive storage class must first be restored before invoking the GetObject API.
Operation types
- Java SDK
- [Python SDK](BOS/SDK/Python-SDK/File management/Download file.md#Range download)
- PHP SDK
- C# SDK
- Android SDK
Example
Taking the Java SDK as an example, you can specify the download range by using GetObjectRequest to achieve more refined acquisition of the object. If the specified download range is 0-100, it will return data from byte 0 to byte 100, including byte 100, with a total of 101 bytes of data, i.e., [0, 100].
1// Create GetObjectRequest
2GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, objectKey);
3 // Obtain data within the 0~100 byte range
4getObjectRequest.setRange(0, 100);
5 //Obtain the object, with returned result BosObject object
6BosObject object = client.getObject(getObjectRequest);
Using the setRange method of getObjectRequest, users can set the range for the returned object. This feature supports segmented downloading and resumable uploading of files.
