Performing a Partial Download
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
When only partial data of an object is required, you can download data falling within a specific range. If the specified range is 0 to 1000, data at the 0th to the 1000th bytes, 1001 bytes in total, will be returned. If the specified range is invalid, data of the whole object will be returned. Sample code is as follows:
// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// Download an object.
try
{
ByteRange byteRange = new ByteRange(10, 200);
GetObjectRequest request = new GetObjectRequest()
{
BucketName = "bucketname",
ObjectKey = "objectname",
ByteRange = byteRange,
};
using (GetObjectResponse response = client.GetObject(request))
{
string dest = "savepath";
if (!File.Exists(dest))
{
response.WriteResponseStreamToFile(dest);
}
Console.WriteLine("Get object response: {0}", response.StatusCode);
}
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
Last Article: Performing a Streaming Download
Next Article: Performing an Asynchronous Download
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.