Download file
The BOS Ruby SDK provides a variety of file download APIs, allowing users to download files from BOS in the following ways:
- Simple streaming download
- Download to a local file
- Resumable download
- Range download
Simple streaming download
Users can read the object into a stream using the following code:
1client.get_object_as_string(bucket_name, object_name)
Directly download an object to a file
Users can download an object to the specified file using the following code:
1client.get_object_to_file(bucket_name, object_name, file_name)
Range download
To implement more functions, you can specify the download range by configuring the RANGE parameter 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]. The format of the RANGE parameter is array(offset, endset), where both variables are long integers in bytes. Users can utilize this function to achieve segmented download and resumable upload of files.
1range = [0,100]
2client.get_object_as_string(bucket_name, object_name, range)
Other methods
Get storage class of the object
The storage class attributes of an object are divided into STANDARD (standard storage), STANDARD_IA (infrequent access storage), and COLD (cold storage). This can be achieved through the following code:
1response = client.get_object_meta_data(bucket_name, object_name)
2puts response[Http::BOS_STORAGE_CLASS];
Obtain only ObjectMetadata
The get_object_meta_data method can be used to obtain only the ObjectMetadata, not the object entity itself. As shown in the following code:
1response = client.get_object_meta_data(bucket_name, object_name)
2puts response['etag'];
The parameters available for calling in the get_object_meta_data parsing class are:
| Parameters | Description |
|---|---|
| content-type | Object type |
| content-length | Object size |
| content-md5 | Object MD5 |
| etag | The HTTP protocol entity tag of object |
| x-bce-storage-class | Storage class of the object |
| user-metadata | If userMetadata custom meta is specified in PutObject, this item will be returned |
