对冷归档对象进行恢复,恢复之后可以通过下载对象接口获取到对象。通过参数可以指定不同的取回方式。
以下代码用于恢复对象。
using System; using TOS; using TOS.Error; using TOS.Model; namespace ConsoleApp { internal class Program { private static void Main(string[] args) { var ak = Environment.GetEnvironmentVariable("TOS_ACCESS_KEY"); var sk = Environment.GetEnvironmentVariable("TOS_SECRET_KEY"); // endpoint 若没有指定HTTP协议(HTTP/HTTPS),默认使用 HTTPS // Bucket 的 Endpoint,以华北2(北京)为例:https://tos-cn-beijing.volces.com var endpoint = "https://tos-cn-beijing.volces.com"; var region = "cn-beijing"; // 填写 BucketName var bucketName = "*** Provide your bucket name ***"; // 填写对象名 var objectKey = "*** Provide your object key ***"; // 创建TOSClient实例 var client = TosClientBuilder.Builder().SetAk(ak).SetSk(sk).SetEndpoint(endpoint).SetRegion(region).Build(); try { // 设置对象恢复 var restoreObjectInput = new RestoreObjectInput { Bucket = bucketName, Key = objectKey, // 指定对象的恢复天数 Days = 1, // 如果桶开启的多版本,通过设置 VersionID 来设置指定版本 VersionID = "", }; var restoreObjectOutput = client.RestoreObject(restoreObjectInput); Console.WriteLine("RestoreObject succeeded, Request ID {0}", restoreObjectOutput.RequestID); } catch (TosServerException ex) { Console.WriteLine("RestoreObject failed, Request ID {0}", ex.RequestID); Console.WriteLine("RestoreObject failed, Status Code {0}", ex.StatusCode); Console.WriteLine("RestoreObject failed, Response Error Code {0}", ex.Code); Console.WriteLine("RestoreObject failed, Response Error Message {0}", ex.Message); } catch (TosClientException ex) { Console.WriteLine("RestoreObject failed, Error Message {0}", ex.Message); } catch (Exception ex) { Console.WriteLine("RestoreObject failed, {0}", ex.Message); } } } }
关于恢复对象接口的详细介绍,请参见 RestoreObject。