OssClient
OSSClient は、OSS サービスの C# クライアントです。OSS サービスの操作のために呼び出される一連の関数を提供します。
OSSClient の作成
以下のコードに示すように、OSSClient は非常に簡単に作成できます。
const string accessId = "<your access id>";
const string accessKey = "<your access key>";
// Using Hangzhou OSS Endpoint as an example
const string endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// Initialize OSSClient instance
var ossClient = new OssClient(endpoint, accessId, accessKey);
ユーザーが AccessKey をインポートし、バケットのエンドポイントにアクセスすることが重要です。
OSSClient の設定
OSSClient の詳細なパラメーターを設定するには、OSSClient の作成時に ClientConfiguration オブジェクトをインポートできます。ClientConfiguration は、OSS サービス設定用の型です。これを使用すると、クライアントのプロキシ、最大接続数、およびその他のパラメーターを設定できます。
ネットワークパラメーターの設定
ClientConfiguration を使用して一部のネットワークパラメーターを設定できます。
conf.ConnectionLimit = 512; // Maximum number of concurrent HttpWebRequest connections
conf. MaxErrorRetry = 3; //Maximum number of retries upon a Set request error
conf. ConnectionTimeout = 300; //Connection timeout time
conf. SetCustomEpochTicks(customEpochTicks); //Set custom reference time
プロキシの使用
以下のコードでは、クライアントはプロキシを使用して OSS サービスにアクセスできます。
// Creates a ClientConfiguration instance
ClientConfiguration conf = new ClientConfiguration();
// Configures the proxy for the local port 8080
conf.ProxyHost = "127.0.0.1";
conf.ProxyPort = 8080;
// Creates the OSSClient
client = new OssClient(endpoint, accessKeySecret, accessKeySecret, conf);