Performing a Streaming 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
Sample code:
// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// Download an object.
try
{
GetObjectRequest request = new GetObjectRequest()
{
BucketName = "bucketname",
ObjectKey = "objectname",
};
using (GetObjectResponse response = client.GetObject(request))
{
string dest = "savepath";
if (!File.Exists(dest))
{
// Write the data streams into the file.
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);
}
GetObjectResponse.OutputStream (System.IO.Stream type) is the response stream in GetObjectResponse. You can obtain the object content to a local file or memory via GetObjectResponse.OutputStream. Alternatively, you can call GetObjectResponse.WriteResponseStreamToFile provided by OBS .NET SDK to download the object content to a local file.
Object response streams obtained by GetObjectResponse.OutputStream must be closed explicitly. Otherwise, resource leakage may occur.
Last Article: Object Download Overview
Next Article: Performing a Partial Download
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.