OBS .NET SDK 0120 Version

Reviewed-by: Sabelnikov, Dmitriy <dmitriy.sabelnikov@t-systems.com>
Co-authored-by: weihongmin1 <weihongmin1@huawei.com>
Co-committed-by: weihongmin1 <weihongmin1@huawei.com>
This commit is contained in:
2026-01-21 15:47:52 +00:00
committed by zuul
parent 43ff755460
commit b2353339c3
130 changed files with 10749 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
version=""
language="en-us"
type=""

View File

@ -0,0 +1,45 @@
<a name="EN-US_TOPIC_0000001831623237"></a><a name="EN-US_TOPIC_0000001831623237"></a>
<h1 class="topictitle1">What Do I Do If the Process Hangs Occasionally?</h1>
<div id="body0000001831623237"><p id="EN-US_TOPIC_0000001831623237__p838516131419"><strong id="EN-US_TOPIC_0000001831623237__b103851138414">Symptom</strong>: The process occasionally hangs when you invoke .NET SDK methods.</p>
<p id="EN-US_TOPIC_0000001831623237__p18463651174117"><strong id="EN-US_TOPIC_0000001831623237__b1573052212418">Solution:</strong> Add "using" before the method.</p>
<p id="EN-US_TOPIC_0000001831623237__p8060118">See the example below.</p>
<pre class="screen" id="EN-US_TOPIC_0000001831623237__screen11897616507"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="EN-US_TOPIC_0000001831623237__b453019341339">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="EN-US_TOPIC_0000001831623237__b175306348317">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of ObsClient.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
<span style="color:#333333;">{</span>
<span style="color:#2B91AF;">GetObjectMetadataRequest</span><span style="color:#333333;"> request = </span><span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetObjectMetadataRequest</span><span style="color:#333333;">();</span>
// Specify a bucket name.
<span style="color:#333333;"> request.BucketName = </span><span style="color:#A31515;">"bucketname"</span><span style="color:#333333;">;</span>
// Specify an object (<strong id="EN-US_TOPIC_0000001831623237__b167264046411195">example/objectname</strong> is an example here).
<span style="color:#333333;"> request.ObjectKey = </span><span style="color:#A31515;">"example/objectname"</span><span style="color:#333333;">;</span>
<span style="color:#008000;"> // Obtain the object metadata.</span>
<span style="color:#2B91AF;">using </span><span style="color:#333333;">(GetObjectMetadataResponse</span><span style="color:#333333;"> response = client.GetObjectMetadata(request)</span><span style="color:#333333;">) {</span>
<span style="color:#2B91AF;"> Console</span><span style="color:#333333;">.WriteLine(</span><span style="color:#A31515;">"Get object metadata response: {0}"</span><span style="color:#333333;">, response.StatusCode);</span>
// Obtain the ETag of the object.
<span style="color:#2B91AF;"> Console</span><span style="color:#333333;">.WriteLine(</span><span style="color:#A31515;">"Object etag {0}: "</span><span style="color:#333333;">, response.ETag);</span>
// Obtain the object version ID.
<span style="color:#2B91AF;">Console</span><span style="color:#333333;">.WriteLine(</span><span style="color:#A31515;">"Object versionId {0}: "</span><span style="color:#333333;">, response.VersionId);</span>
// Obtain the length of the object data, in bytes.
<span style="color:#2B91AF;">Console</span><span style="color:#333333;">.WriteLine(</span><span style="color:#A31515;">"Object contentLength {0}: "</span><span style="color:#333333;">, response.ContentLength);</span>
}
<span style="color:#333333;">}</span>
<span style="color:#0000FF;">catch</span><span style="color:#333333;"> (</span><span style="color:#2B91AF;">ObsException</span><span style="color:#333333;"> ex)</span>
<span style="color:#333333;">{</span>
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"Message: {0}"</span>, ex.Message);
<span style="color:#333333;">} </span> </pre>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_1700.html">FAQ</a></div>
</div>
</div>

View File

@ -0,0 +1,10 @@
<a name="obs_25_0000"></a><a name="obs_25_0000"></a>
<h1 class="topictitle1">Before You Start</h1>
<div id="body0000002018572224"><p id="obs_25_0000__p4829175282110">This section describes version compatibility and important notes about Object Storage Service (OBS) SDK for .NET.</p>
<div class="section" id="obs_25_0000__section1667452184216"><h4 class="sectiontitle">Compatibility</h4><ul id="obs_25_0000__ul2674721144217"><li id="obs_25_0000__li6674192116429">Recommended .NET versions: .NET Framework 3.5, 4.0, or 4.5; .NET Core 2.0 or 3.1; .NET 6 or 7</li><li id="obs_25_0000__li19674621204212">The namespaces used in earlier versions (2.<em id="obs_25_0000__i874375532105811">x.x</em>) are reorganized and all public APIs are now in namespaces <strong id="obs_25_0000__b1170333760105811">OBS</strong> and <strong id="obs_25_0000__b1963610078105811">OBS.Model</strong>.</li><li id="obs_25_0000__li10674112114426">API functions are redesigned and not compatible with those provided by earlier versions (2.<em id="obs_25_0000__i310862330105811">x.x</em>).</li></ul>
</div>
<div class="section" id="obs_25_0000__section328381115452"><h4 class="sectiontitle">Important Notes</h4><ul id="obs_25_0000__ul1814811283515"><li id="obs_25_0000__li2147152815517">Ensure that you are familiar with OBS basic concepts in <a href="https://docs.otc.t-systems.com/en-us/usermanual/obs/en-us_topic_0045853692.html" target="_blank" rel="noopener noreferrer">Help Center</a>, such as buckets, objects, regions, and access keys (AKs/SKs).</li><li id="obs_25_0000__li1384263816519">You can see <a href="obs_25_0113.html">General Examples of ObsClient</a> to learn how to call OBS .NET SDK APIs in a general manner.</li><li id="obs_25_0000__li1318413385618">After an API is called using an instance of <strong id="obs_25_0000__b4535164917101">ObsClient</strong>, if no exception is thrown, the return value is valid. If an exception is thrown, the operation fails, and you can obtain the exception details from the instance of <a href="obs_25_1606.html">ObsException</a>.</li><li id="obs_25_0000__li1670874119211">After an API is successfully called using an instance of <strong id="obs_25_0000__b142515612228">ObsClient</strong>, an instance of <a href="obs_25_1605.html">HeaderResponse</a> that contains response headers will be returned.</li></ul>
</div>
</div>

View File

@ -0,0 +1,8 @@
<a name="obs_25_0001"></a><a name="obs_25_0001"></a>
<h1 class="topictitle1">SDK Download Links</h1>
<div id="body1502764180077"><div class="section" id="obs_25_0001__section1585712245441"><h4 class="sectiontitle">SDK Source Codes</h4><ul id="obs_25_0001__ul10946670563"><li id="obs_25_0001__li26370713216">Latest version of OBS .NET SDK source code: <a href="https://github.com/opentelekomcloud-community/obs-dotnet-sdk" target="_blank" rel="noopener noreferrer">Download</a></li></ul>
</div>
</div>
<div></div>

View File

@ -0,0 +1,29 @@
<a name="obs_25_0100"></a><a name="obs_25_0100"></a>
<h1 class="topictitle1">Quick Start</h1>
<div id="body1502764180078"></div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="obs_25_0103.html">Creating an AK and SK</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0105.html">Installing the SDK</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0106.html">Obtaining Endpoints</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0107.html">Initializing an Instance of ObsClient</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0108.html">Creating a Bucket</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0109.html">Uploading an Object</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0110.html">Downloading an Object</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0111.html">Listing Objects</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0112.html">Deleting an Object</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0113.html">General Examples of ObsClient</a></strong><br>
</li>
</ul>
</div>

View File

@ -0,0 +1,20 @@
<a name="obs_25_0103"></a><a name="obs_25_0103"></a>
<h1 class="topictitle1">Creating an AK and SK</h1>
<div id="body1517297302254"><p id="obs_25_0103__p9732164813445">Access keys consist of two parts: an access key ID (AK) and a secret access key (SK). OBS uses access keys to sign requests to make sure that only authorized accounts can access specified OBS resources. Detailed explanations about AK and SK are as follows:</p>
<ul id="obs_25_0103__ul168171537102114"><li id="obs_25_0103__li13817193792118">An AK defines a user who accesses the OBS system. An AK belongs to only one user, but one user can have multiple AKs. The OBS system recognizes the users who access the system by their access key IDs.</li><li id="obs_25_0103__li10817637182116">An SK is the key used by users to access OBS. It is the authentication information generated based on the AK and the request header. An SK matches an AK, and they group into a pair.</li></ul>
<p id="obs_25_0103__p8503143122312">The procedure is as follows:</p>
<ol id="obs_25_0103__ol9297134219456"><li id="obs_25_0103__li162971429455">Log in to OBS Console.</li><li id="obs_25_0103__li192069368242">In the upper right corner of the page, hover the cursor over the username and choose <strong id="obs_25_0103__b49631759134713">My Credentials</strong>.</li><li id="obs_25_0103__en-us_topic_0142814371_li111081813183213">On the <strong id="obs_25_0103__b92364312483">My Credentials</strong> page, select <strong id="obs_25_0103__b1523612344817">Access Keys</strong> in the navigation pane on the left.</li><li id="obs_25_0103__en-us_topic_0142814371_li875452123217">On the <strong id="obs_25_0103__b594116834813">Access Keys</strong> page, click <strong id="obs_25_0103__b494213814487">Create Access Key</strong>.</li><li id="obs_25_0103__li6297342164517">In the <strong id="obs_25_0103__b128431810154816">Create Access Key</strong> dialog box that is displayed, enter the password and verification code.<div class="note" id="obs_25_0103__note1973823819195"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0103__ul0792103811194"><li id="obs_25_0103__li17792123819197">If you have not bound an email address or mobile number, you need to enter only the login password.</li><li id="obs_25_0103__li479210389194">If you have bound an email address and a mobile number, you can select the verification by either email or mobile phone.</li></ul>
</div></div>
</li><li id="obs_25_0103__li1871318184251">Click <strong id="obs_25_0103__b1611812553599">OK</strong>.</li><li id="obs_25_0103__li14714171832518">In the <strong id="obs_25_0103__b10785132212486">Download Access Key</strong> dialog box that is displayed, click <strong id="obs_25_0103__b17867228482">OK</strong> to save the access keys to your browser's default download path.</li><li id="obs_25_0103__li117144186258">Open the downloaded <strong id="obs_25_0103__b723942584813">credentials.csv</strong> file to obtain the access keys (AK and SK).</li></ol>
<div class="note" id="obs_25_0103__note6500160171911"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0103__ul20741103324711"><li id="obs_25_0103__li11741533154716">A user can create a maximum of two valid access keys.</li><li id="obs_25_0103__li3741113324712">Keep the access key properly. If you click <strong id="obs_25_0103__b67228354487">Cancel</strong> in the dialog box, the access keys will not be downloaded, and cannot be obtained later. You can re-create access keys if you need to use them.</li></ul>
</div></div>
<ul id="obs_25_0103__ul57314172475"><li id="obs_25_0103__li37311178473">To get temporary access keys, refer to the following:<p id="obs_25_0103__en-us_topic_0000001605096753_en-us_topic_0000001526886348_p1387017162467"><a name="obs_25_0103__li37311178473"></a><a name="li37311178473"></a>Temporary access keys are issued by the system and are only valid for 15 minutes to 24 hours. Once expired, they must be requested again. They follow the principle of least privilege. When a temporary AK/SK pair is used for authentication, a security token must be used at the same time.</p>
</li></ul>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,13 @@
<a name="obs_25_0105"></a><a name="obs_25_0105"></a>
<h1 class="topictitle1">Installing the SDK</h1>
<div id="body1502764180077"><p id="obs_25_0105__p114301125203"></p>
<p id="obs_25_0105__p159513611397">Installing the OBS .NET SDK. The example here uses the latest version.</p>
<ol id="obs_25_0105__ol3886673015130"><li id="obs_25_0105__li10532141693914"><span>Download the OBS .NET SDK development package. For details, see <a href="obs_25_0001.html">SDK Download Links</a>.</span></li><li id="obs_25_0105__li19532111617392"><span>Decompress the development package to obtain folder <strong id="obs_25_0105__b1255741916210">demo</strong> (sample code) and file <strong id="obs_25_0105__b1851618511211">Log4Net.config</strong> (log configuration file). Start Visual Studio, open the project solution, and open the <strong id="obs_25_0105__b785614274278">esdk_obs_.net.sln</strong> or <strong id="obs_25_0105__b6881133072717">esdk_obs_.net_core.sln</strong> file in the directory based on the project framework. Set the solution to <strong id="obs_25_0105__b5367141211288">Release</strong> and generate a solution. You can find <strong id="obs_25_0105__b14374184013307">esdk_obs_.net.dll</strong> and <strong id="obs_25_0105__b036214493018">log4net.dll</strong> files in <strong id="obs_25_0105__b1924113379304">bin/Release</strong> in the decompression directory.</span></li><li id="obs_25_0105__li1509083515130"><span>Start Visual Studio and choose <strong id="obs_25_0105__b09441581152">FILE</strong> &gt; <strong id="obs_25_0105__b11561811853">New</strong> &gt;<strong id="obs_25_0105__b836801319517"> Project </strong>&gt; <strong id="obs_25_0105__b47601915958">Templates</strong> &gt; <strong id="obs_25_0105__b1295111819515">Visual C#</strong> &gt;<strong id="obs_25_0105__b17547922455"> Console Application </strong>to create a Console Application project.</span></li><li id="obs_25_0105__li3224243192042"><span>Right-click the new project and choose <strong id="obs_25_0105__b830819102612">References </strong>&gt; <strong id="obs_25_0105__b166813714612">Add Reference</strong> and import file <strong id="obs_25_0105__b1221163664">esdk_obs_.net.dll</strong>.</span></li></ol>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,13 @@
<a name="obs_25_0106"></a><a name="obs_25_0106"></a>
<h1 class="topictitle1">Obtaining Endpoints</h1>
<div id="body1502764180078"><ul id="obs_25_0106__ul384585317111"><li id="obs_25_0106__li1981154765611">You can click <a href="https://docs.otc.t-systems.com/en-us/endpoint/index.html" target="_blank" rel="noopener noreferrer">here</a> to view the endpoints and regions enabled for OBS.</li></ul>
<div class="notice" id="obs_25_0106__note545317864015"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="obs_25_0106__p425561863518">The SDK allows you to pass endpoints with or without the protocol name. Suppose the endpoint you obtained is <strong id="obs_25_0106__b18292053719">your-endpoint</strong>. The endpoint passed when initializing an instance of <strong id="obs_25_0106__b185224183397">ObsClient</strong> can be <strong id="obs_25_0106__b541543815399">http://your-endpoint</strong>, <strong id="obs_25_0106__b12312114316393">https://your-endpoint</strong>, or <strong id="obs_25_0106__b1743684617395">your-endpoint</strong>.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,24 @@
<a name="obs_25_0107"></a><a name="obs_25_0107"></a>
<h1 class="topictitle1">Initializing an Instance of ObsClient</h1>
<div id="body1502764180078"><p id="obs_25_0107__p8060118">Each time you want to send an HTTP/HTTPS request to OBS, you must create an instance of <strong id="obs_25_0107__b842352706163424">ObsClient</strong>. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0107__screen19344497154448"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0107__b889321364018">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0107__b1789391354014">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><strong style="color:#008000;" id="obs_25_0107__b17663183516819">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// Use the instance to access OBS.</span></pre>
<div class="note" id="obs_25_0107__note4861899010"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0107__p15280155018331">For more information, see chapter "Initialization."</p>
<p id="obs_25_0107__p9382627155613">For details about logging configuration, see <a href="obs_25_0204.html">Configuring SDK Logging</a>.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,17 @@
<a name="obs_25_0108"></a><a name="obs_25_0108"></a>
<h1 class="topictitle1">Creating a Bucket</h1>
<div id="body1502764180078"><p id="obs_25_0108__p8060118">A bucket is a global namespace of OBS and is a data container. It functions as a root directory of a file system and can store objects. The following code shows how to create a bucket:</p>
<pre class="screen" id="obs_25_0108__screen19344497154448"><span style="color:#2B91AF;">CreateBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CreateBucketRequest</span>();
request.BucketName = <span style="color:#A31515;">"bucketname"</span>;
client.CreateBucket(request);</pre>
<div class="note" id="obs_25_0108__note1891015431910"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0108__ul173018402204"><li id="obs_25_0108__li1010192875314">Bucket names are globally unique. Ensure that the bucket you create is named differently from any other bucket.</li><li id="obs_25_0108__li845918159115">A bucket name must comply with the following rules:<ul id="obs_25_0108__ul14460215514"><li id="obs_25_0108__li11460515417">Contains 3 to 63 characters, chosen from lowercase letters, digits, hyphens (-), and periods (.), and starts with a digit or letter.</li><li id="obs_25_0108__li1460815318">Cannot be an IP address or similar.</li><li id="obs_25_0108__li946016151114">Cannot start or end with a hyphen (-) or period (.)</li><li id="obs_25_0108__li1460315418">Cannot contain two consecutive periods (.), for example, <strong id="obs_25_0108__b842352706191036">my..bucket</strong>.</li><li id="obs_25_0108__li3460151519119">Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, <strong id="obs_25_0108__b842352706191112">my-.bucket</strong> or <strong id="obs_25_0108__b842352706191116">my.-bucket</strong>.</li></ul>
</li><li id="obs_25_0108__li48451415202918">If you create buckets of the same name, no error will be reported and the bucket properties comply with those set in the first creation request.</li><li id="obs_25_0108__li82886715244">For more information, see <a href="obs_25_0301.html">Creating a Bucket</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,21 @@
<a name="obs_25_0109"></a><a name="obs_25_0109"></a>
<h1 class="topictitle1">Uploading an Object</h1>
<div id="body1502764180078"><p id="obs_25_0109__p16151326559">This example uploads string <strong id="obs_25_0109__b202081013313">Hello OBS</strong> to bucket <strong id="obs_25_0109__b1920891534">bucketname</strong> as object <strong id="obs_25_0109__b13208214311">objectname</strong>.</p>
<p id="obs_25_0109__p131611447317">The example code is as follows:</p>
<pre class="screen" id="obs_25_0109__screen275317242913"><span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
InputStream = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">MemoryStream</span>(<span style="color:#2B91AF;">Encoding</span>.UTF8.GetBytes(<span style="color:#A31515;">"Hello OBS"</span>))
};
client.PutObject(request);</pre>
<div class="note" id="obs_25_0109__note12753142412915"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0109__ul119431152152518"><li id="obs_25_0109__li1094355212517">For more information, see <a href="obs_25_0401.html">Object Upload Overview</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,28 @@
<a name="obs_25_0110"></a><a name="obs_25_0110"></a>
<h1 class="topictitle1">Downloading an Object</h1>
<div id="body1502764180078"><p id="obs_25_0110__p12395912181919">This example downloads object <strong id="obs_25_0110__b16167154519317">objectname</strong> from bucket <strong id="obs_25_0110__b13167184516310">bucketname</strong>.</p>
<p id="obs_25_0110__p18320110121913">The example code is as follows:</p>
<pre class="screen" id="obs_25_0110__screen24072670103450"><span style="color:#2B91AF;">GetObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
};
<span style="color:#0000FF;">using</span> (<span style="color:#2B91AF;">GetObjectResponse</span> response = client.GetObject(request))
{
<span style="color:#008000;">//</span><span style="color:#008000;">Save the object locally.</span>
<span style="color:#0000FF;">string</span> dest = <span style="color:#A31515;">"savepath"</span>;
<span style="color:#0000FF;">if</span> (!<span style="color:#2B91AF;">File</span>.Exists(dest))
{
response.WriteResponseStreamToFile(dest);
}
}</pre>
<div class="note" id="obs_25_0110__note1722122018256"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0110__p97461649428">For more information, see <a href="obs_25_0501.html">Object Download Overview</a>.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,20 @@
<a name="obs_25_0111"></a><a name="obs_25_0111"></a>
<h1 class="topictitle1">Listing Objects</h1>
<div id="body1502764180078"><p id="obs_25_0111__p8060118">After objects are uploaded, you may want to view the objects contained in a bucket. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0111__screen6529298110411"><span style="color:#2B91AF;">ListObjectsRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ListObjectsRequest</span>();
request.BucketName = <span style="color:#A31515;">"bucketname"</span>;
<span style="color:#2B91AF;">ListObjectsResponse</span> response = client.ListObjects(request);
<span style="color:#0000FF;">foreach</span> (<span style="color:#2B91AF;">ObsObject</span> Object <span style="color:#0000FF;">in</span> response.ObsObjects)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ObjectKey={0}, Size={1}"</span>, Object.ObjectKey, Object.Size);
}</pre>
<div class="note" id="obs_25_0111__note1730335918312"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0111__ul12303175916312"><li id="obs_25_0111__li19576443164516">You can call <strong id="obs_25_0111__b1589392141216">ListObjectsResponse.ObsObjects</strong> to obtain the descriptions of all objects.</li><li id="obs_25_0111__li43031559133119">In the previous sample code, 1000 objects will be listed, by default.</li><li id="obs_25_0111__li5784101684918">For more information, see <a href="obs_25_0603.html">Listing Objects</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,20 @@
<a name="obs_25_0112"></a><a name="obs_25_0112"></a>
<h1 class="topictitle1">Deleting an Object</h1>
<div id="body1502764180078"><p id="obs_25_0112__p1877310813324">This example deletes object <strong id="obs_25_0112__b127441819841">objectname</strong> from bucket <strong id="obs_25_0112__b137444192413">bucketname</strong>.</p>
<p id="obs_25_0112__p17462102183312">The example code is as follows:</p>
<pre class="screen" id="obs_25_0112__screen38086206523"><span style="color:#2B91AF;">DeleteObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">DeleteObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
};
client.DeleteObject(request);</pre>
<div class="note" id="obs_25_0112__note1276952613186"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0112__ul717611415249"><li id="obs_25_0112__li71761642242">This example only deletes a single object. To delete objects in a batch, traverse objects and list to-be-deleted objects on your own.</li><li id="obs_25_0112__li19541153513254">For details about deletion, see <a href="obs_25_0604.html">Deleting Objects</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,69 @@
<a name="obs_25_0113"></a><a name="obs_25_0113"></a>
<h1 class="topictitle1">General Examples of ObsClient</h1>
<div id="body1503556657957"><p id="obs_25_0113__p8060118">When you call an API using an instance of <strong id="obs_25_0113__b842352706161555">ObsClient</strong>, if no exception is thrown, the return value is valid, and a sub-class instance of <a href="obs_25_1605.html">ObsWebServiceResponse</a> (SDK common response headers) is returned. If any exception is thrown, the operation failed, and you can obtain the exception details from the returned instance of <a href="obs_25_1606.html">ObsException</a>. <strong id="obs_25_0113__b842352706153049">ObsClient</strong> supports synchronous and asynchronous API callings. Examples are as follows:</p>
<div class="section" id="obs_25_0113__section418491041815"><h4 class="sectiontitle">Synchronous Call</h4><p id="obs_25_0113__p13459122121919">Sample code:</p>
</div>
<pre class="screen" id="obs_25_0113__screen1548910418399"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0113__b125751855194118">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0113__b19575555164119">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><strong style="color:#008000;" id="obs_25_0113__b6920183518154_1">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Call the API for creating a bucket in synchronous mode.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">CreateBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CreateBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">CreateBucketResponse</span> response = client.CreateBucket(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Create bucket response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="section" id="obs_25_0113__section95768464194"><h4 class="sectiontitle">Asynchronous Call</h4><div class="p" id="obs_25_0113__p3965195720199">Sample code:<pre class="screen" id="obs_25_0113__screen5601124619268"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0113__b1178451094216">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0113__b11784111014423">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><strong style="color:#008000;" id="obs_25_0113__b6920183518154_3">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Call the API for creating a bucket in asynchronous mode.</span>
<span style="color:#2B91AF;">CreateBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CreateBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
client.BeginCreateBucket(request, <span style="color:#0000FF;">delegate</span>(<span style="color:#2B91AF;">IAsyncResult</span> ar){
<span style="color:#0000FF;"> try</span>
{
<span style="color:#2B91AF;">CreateBucketResponse</span> response = client.EndCreateBucket(ar);
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"Create bucket response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;"> catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}
}, <span style="color:#0000FF;">null</span>);
Console.ReadKey();</pre>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0100.html">Quick Start</a></div>
</div>
</div>

View File

@ -0,0 +1,17 @@
<a name="obs_25_0200"></a><a name="obs_25_0200"></a>
<h1 class="topictitle1">Initialization</h1>
<div id="body1502764180078"></div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="obs_25_0201.html">Configuring the AK/SK</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0202.html">Creating an Instance of ObsClient</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0203.html">Configuring an Instance of ObsClient</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0204.html">Configuring SDK Logging</a></strong><br>
</li>
</ul>
</div>

View File

@ -0,0 +1,15 @@
<a name="obs_25_0201"></a><a name="obs_25_0201"></a>
<h1 class="topictitle1">Configuring the AK/SK</h1>
<div id="body1502764180078"><p id="obs_25_0201__p14133257141611">To use OBS, you need a valid pair of AK and SK for signature authentication.</p>
<p id="obs_25_0201__p16491103174"></p>
<p id="obs_25_0201__p58961533152918">For details, see <a href="obs_25_0103.html">Creating an AK and SK</a>.</p>
<p id="obs_25_0201__p16896183352918">After obtaining the AK/SK pair, you can start initialization by taking these steps:</p>
<ul id="obs_25_0201__ul41794515273"><li id="obs_25_0201__li13179165110275"><a href="obs_25_0202.html">Creating an Instance of ObsClient</a></li><li id="obs_25_0201__li18179155113277"><a href="obs_25_0203.html">Configuring an Instance of ObsClient</a></li><li id="obs_25_0201__li11637135752713"><a href="obs_25_0204.html">Configuring SDK Logging</a></li></ul>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0200.html">Initialization</a></div>
</div>
</div>

View File

@ -0,0 +1,46 @@
<a name="obs_25_0202"></a><a name="obs_25_0202"></a>
<h1 class="topictitle1">Creating an Instance of ObsClient</h1>
<div id="body1502764180078"><p id="obs_25_0202__p7187175655615"><strong id="obs_25_0202__b1754422013104313">ObsClient</strong> functions as the .NET client for accessing OBS. It offers callers a series of APIs for interaction with OBS and is used for managing and operating resources, such as buckets and objects, stored in OBS. To use OBS .NET SDK to send a request to OBS, you need to initialize an instance of <strong id="obs_25_0202__b1223242415104313">ObsClient</strong> and modify the default configurations in <strong id="obs_25_0202__b246242018104313">ObsConfig</strong> based on needs.</p>
<p id="obs_25_0202__p66831906573"></p>
<ul id="obs_25_0202__ul1926835212213"><li id="obs_25_0202__li11268452162217">If you use the endpoint to create an instance of <strong id="obs_25_0202__b892425210544">ObsClient</strong>, all parameters are in their default values and cannot be modified.<ul id="obs_25_0202__ul87395319511"><li id="obs_25_0202__li1370912105118">Using permanent AK (access key ID)/SK(secret access key)</li></ul>
<pre class="screen" id="obs_25_0202__screen169401731101720"><span style="color:#008000;">// Initialize configuration parameters.</span>
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0202__b142951235164317">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0202__b1029583514316">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><strong style="color:#008000;" id="obs_25_0202__b578814341381">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, <span style="color:#A31515;">"https://your-endpoint"</span>);
<span style="color:#008000;">// </span><span style="color:#008000;">Use the instance to access </span><span style="color:#008000;">OBS.</span></pre>
<ul id="obs_25_0202__ul1117095452213"><li id="obs_25_0202__li157132544815">Using temporary access credentials (AKs/SKs and security tokens)</li></ul>
<pre class="screen" id="obs_25_0202__screen2490143910489"><span style="color:#008000;">// Initialize configuration parameters.</span>
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0202__b18502122117810">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0202__b150213211888">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> <span style="color:#252B3A;">securityToken</span>= "your<span style="color:#252B3A;">_securityToken</span>"
<span style="color:#008000;">// Create an instance of ObsClient.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey,<span style="color:#252B3A;">securityToken</span>, <span style="color:#A31515;">"https://your-endpoint"</span>);
<span style="color:#008000;">// Use the instance to access OBS.</span></pre>
</li></ul>
<ul id="obs_25_0202__ul1295404704919"><li id="obs_25_0202__li795411478493">If you use the <strong id="obs_25_0202__b84235270692449">ObsConfig</strong> configuration class to create an instance of <strong id="obs_25_0202__b8423527069256">ObsClient</strong>, you can set any parameters as needed during the creation. After the instance has been created, the parameters cannot be modified. For parameter details, see <a href="obs_25_0203.html">Configuring an Instance of ObsClient</a></li></ul>
<pre class="screen" id="obs_25_0202__screen64555571195328"><span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong id="obs_25_0202__b14466955111313"><span style="color:#008000;">ObsConfig</span></strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0202__b1260324215432">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0202__b660364284313">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><strong style="color:#008000;" id="obs_25_0202__b2804157159">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// Use the </span><span style="color:#008000;">instance to access OBS.</span></pre>
<div class="note" id="obs_25_0202__note1398481384510"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0202__ul288174110455"><li id="obs_25_0202__li6881541114520">The project can contain one or more instances of <strong id="obs_25_0202__b842352706154845">ObsClient</strong>.</li></ul>
<ul id="obs_25_0202__ul2098461304514"><li id="obs_25_0202__li17984161313454"><strong id="obs_25_0202__b842352706113816">ObsClient</strong> is thread-safe and can be simultaneously used by multiple threads.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0200.html">Initialization</a></div>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
<a name="obs_25_0204"></a><a name="obs_25_0204"></a>
<h1 class="topictitle1">Configuring SDK Logging</h1>
<div id="body1502764180078"><p id="obs_25_0204__p52301238171813">OBS .NET SDK provides the logging function, based on the Apache Log4net open library. You can add log configuration files to enable the logging function. The procedure is as follows:</p>
<ol id="obs_25_0204__ol175970537230"><li id="obs_25_0204__li165121058133215"><span>Add a reference to <strong id="obs_25_0204__b9599145045818">log4net.dll</strong> in the project.</span></li><li id="obs_25_0204__li8683212122511"><span>Copy configuration file <strong id="obs_25_0204__b118313281308">Log4Net.config</strong> to <strong id="obs_25_0204__b1245613119012">Debug</strong> or <strong id="obs_25_0204__b1543915341208">Release</strong> under directory <strong id="obs_25_0204__b017212408017">bin</strong> of the project, to ensure that the configuration file and the project's executable files are in the same directory.</span></li><li id="obs_25_0204__li1869113117267"><span>Modify log levels in file <strong id="obs_25_0204__b922255618212">Log4Net.config</strong> based on needs.</span></li></ol>
<div class="note" id="obs_25_0204__note1911620337524"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0204__ul1511653319526"><li id="obs_25_0204__li151165339524">Without these operations, the logging function is in the disabled state and no logs will be generated.</li><li id="obs_25_0204__li1116133105219">For details about SDK logs, see <a href="obs_25_1602.html">Log Analysis</a>.</li><li id="obs_25_0204__li5463204165415">The save path of log files defaults to be that of the project's executable files and can be changed in <strong id="obs_25_0204__b149024237620">Log4Net.config</strong>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0200.html">Initialization</a></div>
</div>
</div>

View File

@ -0,0 +1,31 @@
<a name="obs_25_0300"></a><a name="obs_25_0300"></a>
<h1 class="topictitle1">Bucket Management</h1>
<div id="body1502764180078"></div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="obs_25_0301.html">Creating a Bucket</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0302.html">Listing Buckets</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0303.html">Deleting a Bucket</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0304.html">Identifying Whether a Bucket Exists</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0305.html">Obtaining Bucket Metadata</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0306.html">Managing Bucket ACLs</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0307.html">Management Bucket Policies</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0308.html">Obtaining a Bucket Location</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0309.html">Obtaining Storage Information About a Bucket</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0310.html">Setting or Obtaining a Bucket Quota</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0311.html">Setting or Obtaining the Storage Class of a Bucket</a></strong><br>
</li>
</ul>
</div>

View File

@ -0,0 +1,72 @@
<a name="obs_25_0301"></a><a name="obs_25_0301"></a>
<h1 class="topictitle1">Creating a Bucket</h1>
<div id="body1502764180078"><p id="obs_25_0301__p8060118">You can call <strong id="obs_25_0301__b842352706174312">ObsClient.CreateBucket</strong> to create a bucket.</p>
<div class="section" id="obs_25_0301__section188341918155711"><h4 class="sectiontitle">Creating a Bucket with Parameters Specified</h4><div class="p" id="obs_25_0301__p1983481818575">When creating a bucket, you can specify the ACL, storage class, and location for the bucket. OBS provides three storage classes for buckets. For details, see <a href="obs_25_0311.html">Setting or Obtaining the Storage Class of a Bucket</a>. Sample code is as follows:<pre class="screen" id="obs_25_0301__screen1183401812573"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0301__b135961032155211">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0301__b19596232185215">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of ObsClient.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Create a bucket.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">CreateBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CreateBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
<span style="color:#008000;">// </span><span style="color:#008000;">Set the bucket location.</span>
Location = <span style="color:#A31515;">"bucketLocation"</span>,
<span style="color:#008000;">// Set the storage class to Cold.</span>
StorageClass = <span style="color:#2B91AF;">StorageClassEnum</span>.Cold,
<span style="color:#008000;">// Set the ACL for the bucket to public read (the default state is private).</span>
CannedAcl = <span style="color:#2B91AF;">CannedAclEnum</span>.Private
};
<span style="color:#2B91AF;">CreateBucketResponse</span> response = client.CreateBucket(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Create bucket response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
</div>
</div>
<div class="note" id="obs_25_0301__note5202194618573"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0301__ul19202154665717"><li id="obs_25_0301__li2020216465574">Bucket names are globally unique. Ensure that the bucket you create is named differently from any other bucket.</li><li id="obs_25_0301__li82021246165713">A bucket name must comply with the following rules:<ul id="obs_25_0301__ul1120224645714"><li id="obs_25_0301__li14202846185710">Contains 3 to 63 characters, chosen from lowercase letters, digits, hyphens (-), and periods (.), and starts with a digit or letter.</li><li id="obs_25_0301__li920214675712">Cannot be an IP address or similar.</li><li id="obs_25_0301__li7202846135718">Cannot start or end with a hyphen (-) or period (.)</li><li id="obs_25_0301__li2202164665716">Cannot contain two consecutive periods (.), for example, <strong id="obs_25_0301__b842352706191036">my..bucket</strong>.</li><li id="obs_25_0301__li820214635716">Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, <strong id="obs_25_0301__b842352706191112">my-.bucket</strong> or <strong id="obs_25_0301__b842352706191116">my.-bucket</strong>.</li></ul>
</li><li id="obs_25_0301__li12029469577">If you create buckets of the same name in a region, no error will be reported and the bucket properties comply with those set in the first creation request.</li><li id="obs_25_0301__li92033464574">The bucket created in the previous example is of the default <a href="obs_25_0306.html">ACL</a> (<strong id="obs_25_0301__b1374053105020">private</strong>), in the OBS Standard storage class, and in the default region.</li></ul>
</div></div>
<div class="section" id="obs_25_0301__section121861951413"><h4 class="sectiontitle">Creating a Bucket Directly</h4><p id="obs_25_0301__p15186391142">Sample code:</p>
<pre class="screen" id="obs_25_0301__screen19344497154448"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0301__b0490035175215">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0301__b9490935165219">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// Create an instance of </span><span style="color:#008000;">ObsClient.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Create a bucket.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">CreateBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CreateBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">CreateBucketResponse</span> response = client.CreateBucket(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Create bucket response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,42 @@
<a name="obs_25_0302"></a><a name="obs_25_0302"></a>
<h1 class="topictitle1">Listing Buckets</h1>
<div id="body1502764180079"><p id="obs_25_0302__p8060118">You can call <strong id="obs_25_0302__b842352706102522">ObsClient.ListBuckets</strong> to list buckets. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0302__screen19344497154448"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0302__b16602195064316">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0302__b1560212505430">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0302__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">List buckets.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">ListBucketsRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ListBucketsRequest</span>();
<span style="color:#2B91AF;">ListBucketsResponse</span> response = client.ListBuckets(request);
request.IsQueryLocation = <span style="color:#0000FF;">true</span>;
<span style="color:#0000FF;">foreach</span> (<span style="color:#2B91AF;">ObsBucket</span> bucket <span style="color:#0000FF;">in</span> response.Buckets)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Bucket name is : {0}"</span>, bucket.BucketName);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Bucket creationDate is : {0}"</span>, bucket.CreationDate);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Bucket location is : {0}"</span>, bucket.Location);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"\n"</span>);
}
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}
</pre>
<div class="note" id="obs_25_0302__note1544312496717"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0302__ul54234220456"><li id="obs_25_0302__li1742144274512">Obtained bucket names are listed in the lexicographical order.</li><li id="obs_25_0302__li195574451451">Set <strong id="obs_25_0302__b842352706111625">ListBucketsRequest.IsQueryLocation</strong> to <strong id="obs_25_0302__b842352706203257">true</strong> and then you can query the bucket location when listing buckets.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,37 @@
<a name="obs_25_0303"></a><a name="obs_25_0303"></a>
<h1 class="topictitle1">Deleting a Bucket</h1>
<div id="body1502764180079"><p id="obs_25_0303__p8060118">You can call <strong id="obs_25_0303__b842352706102552">ObsClient.DeleteBucket</strong> to delete a bucket. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0303__screen19344497154448"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0303__b892212553431">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0303__b49221355164317">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0303__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">//</span><span style="color:#008000;">Delete a bucket.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">DeleteBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">DeleteBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">DeleteBucketResponse</span> response = client.DeleteBucket(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Delete bucket response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0303__note73212174208"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0303__ul15405221112011"><li id="obs_25_0303__li16974163352010">Only empty buckets (without objects and part fragments) can be deleted.</li><li id="obs_25_0303__li526474910275">Bucket deletion is a non-idempotence operation and an error will be reported if the to-be-deleted bucket does not exist.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,38 @@
<a name="obs_25_0304"></a><a name="obs_25_0304"></a>
<h1 class="topictitle1">Identifying Whether a Bucket Exists</h1>
<div id="body1502868754469"><p id="obs_25_0304__p152351025013">You can call <strong id="obs_25_0304__b84235270610276">ObsClient.HeadBucket</strong> to identify whether a bucket exists.</p>
<p id="obs_25_0304__p1261713762916">This example checks whether bucket <strong id="obs_25_0304__b149114582092">bucketname</strong> exists.</p>
<p id="obs_25_0304__p55461842174114">The example code is as follows:</p>
<pre class="screen" id="obs_25_0304__screen543613403498"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0304__b435490204417">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0304__b193545010442">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0304__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config
<span style="color:#008000;">// </span><span style="color:#008000;">Identify whether a bucket exists.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">HeadBucketRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">HeadBucketRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">bool</span> exists = client.HeadBucket(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Bucket exists: {0}"</span>, exists);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"StatusCode: {0}"</span>, ex.StatusCode);
}</pre>
<div class="note" id="obs_25_0304__note98741357111513"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0304__p529814231050">If an exception is thrown and the returned HTTP status code is <strong id="obs_25_0304__b1181065719135">404</strong>, the bucket does not exist.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,43 @@
<a name="obs_25_0305"></a><a name="obs_25_0305"></a>
<h1 class="topictitle1">Obtaining Bucket Metadata</h1>
<div id="body1502764180079"><p id="obs_25_0305__p8060118">You can call <strong id="obs_25_0305__b842352706102731">ObsClient.GetBucketMetadata</strong> to obtain the metadata of a bucket.</p>
<p id="obs_25_0305__p1261713762916">This example returns the metadata of bucket <strong id="obs_25_0305__b137206365125">bucketname</strong>.</p>
<p id="obs_25_0305__p152351025013">The example code is as follows:</p>
<pre class="screen" id="obs_25_0305__screen543613403498"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0305__b37605410444">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0305__b17760114164416">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0305__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Obtain the bucket metadata.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">List</span>&lt;<span style="color:#0000FF;">string</span>&gt; headers = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">List</span>&lt;<span style="color:#0000FF;">string</span>&gt;();
headers.Add(<span style="color:#A31515;">"x-obs-header"</span>);
<span style="color:#2B91AF;">GetBucketMetadataRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetBucketMetadataRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
Origin = <span style="color:#A31515;">"http://www.a.com"</span>,
AccessControlRequestHeaders = headers,
};
<span style="color:#2B91AF;">GetBucketMetadataResponse</span> response = client.GetBucketMetadata(request);
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"StorageClass: {0}"</span>, response.StorageClass);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Location: {0}"</span>, response.Location);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"StatusCode: {0}"</span>, ex.StatusCode);
} </pre>
<div class="note" id="obs_25_0305__note10171816161418"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0305__ul189284155157"><li id="obs_25_0305__li8928141510150">To handle the error codes possibly returned during the operation, see <a href="obs_25_1601.html">OBS Server-Side Error Codes</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
<a name="obs_25_0307"></a><a name="obs_25_0307"></a>
<h1 class="topictitle1">Management Bucket Policies</h1>
<div id="body1532661695852"><p id="obs_25_0307__p97574819501">Besides bucket ACLs, bucket owners can use bucket policies to centrally control access to buckets and objects in buckets.</p>
<p id="obs_25_0307__p16697627358">For more information, see <a href="https://docs.otc.t-systems.com/en-us/perms-cfg/obs/obs_40_0004.html" target="_blank" rel="noopener noreferrer">Bucket Policies</a>.</p>
<div class="section" id="obs_25_0307__section8517109534"><h4 class="sectiontitle">Setting a Bucket Policy</h4><p id="obs_25_0307__p25183913318">You can call <strong id="obs_25_0307__b842352706144031">ObsClient.SetBucketPolicy</strong> to set a bucket policy. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0307__screen95103357215"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0307__b13972894446">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0307__b1297219164417">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008001;">// </span><span style="color:#008001;">Create an instance of </span><strong style="color:#008001;" id="obs_25_0307__b018213463919">ObsClient</strong><span style="color:#008001;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">SetBucketPolicyRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">SetBucketPolicyRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
Policy = <span style="color:#A31515;">"your policy"</span>,
};
<span style="color:#2B91AF;">SetBucketPolicyResponse</span> response = client.SetBucketPolicy(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Set bucket policy response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0307__note132271983519"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0307__p244341033413">For details about the format (JSON character string) of bucket policies, see the <em id="obs_25_0307__i842352697174053">Object Storage Service API Reference</em>.</p>
</div></div>
</div>
<div class="section" id="obs_25_0307__section105838221315"><h4 class="sectiontitle">Obtaining a Bucket Policy</h4><p id="obs_25_0307__p1973015210235">You can call <strong id="obs_25_0307__b1016359236">ObsClient.GetBucketPolicy</strong> to obtain a bucket policy. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0307__screen4731152152311"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0307__b1178171414441">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0307__b47811414410">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008001;">// </span><span style="color:#008001;">Create an instance of </span><strong style="color:#008001;" id="obs_25_0307__b414757823">ObsClient</strong><span style="color:#008001;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">GetBucketPolicyRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetBucketPolicyRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">GetBucketPolicyResponse</span> response = client.GetBucketPolicy(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Get bucket policy response: {0}"</span>, response.StatusCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Policy: {0}"</span>, response.Policy);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
</div>
<div class="section" id="obs_25_0307__section145601218375"><h4 class="sectiontitle">Deleting a Bucket Policy</h4><p id="obs_25_0307__p956191213375">You can call <strong id="obs_25_0307__b2112194475">ObsClient.DeleteBucketPolicy</strong> to delete a bucket policy. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0307__screen17569126377"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0307__b744921944412">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0307__b44491519104410">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008001;">// </span><span style="color:#008001;">Create an instance of </span><strong style="color:#008001;" id="obs_25_0307__b405242691">ObsClient</strong><span style="color:#008001;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">DeleteBucketPolicyRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">DeleteBucketPolicyRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">DeleteBucketPolicyResponse</span> response = client.DeleteBucketPolicy(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Delete bucket policy response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,40 @@
<a name="obs_25_0308"></a><a name="obs_25_0308"></a>
<h1 class="topictitle1">Obtaining a Bucket Location</h1>
<div id="body1502764180079"><p id="obs_25_0308__p8060118">You can call <strong id="obs_25_0308__b842352706103356">ObsClient.GetBucketLocation</strong> to obtain the location of a bucket.</p>
<p id="obs_25_0308__p1261713762916">This example returns the region of bucket <strong id="obs_25_0308__b9528145192012">bucketname</strong>.</p>
<p id="obs_25_0308__p152351025013">The example code is as follows:</p>
<pre class="screen" id="obs_25_0308__screen543613403498"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0308__b8718425104414">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0308__b117181725114412">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of ObsClient.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Obtain the bucket location.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">GetBucketLocationRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetBucketLocationRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">GetBucketLocationResponse</span> response = client.GetBucketLocation(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Get bucket location response: {0}"</span>, response.StatusCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Location: {0}"</span>, response.Location);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0308__note737713917437"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0308__p125441901983">When creating a bucket, you can specify its location. For details, see <a href="obs_25_0301.html">Creating a Bucket</a>.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,42 @@
<a name="obs_25_0309"></a><a name="obs_25_0309"></a>
<h1 class="topictitle1">Obtaining Storage Information About a Bucket</h1>
<div id="body1502764180079"><p id="obs_25_0309__p19714114761212">The storage information about a bucket includes the used capacity of and the number of objects in the bucket.</p>
<p id="obs_25_0309__p990417511401">You can call <strong id="obs_25_0309__b842352706103448">ObsClient.GetBucketStorageInfo</strong> to obtain the bucket storage information.</p>
<p id="obs_25_0309__p1261713762916">This example returns the storage information of bucket <strong id="obs_25_0309__b150116294502">bucketname</strong>.</p>
<p id="obs_25_0309__p152351025013">The example code is as follows:</p>
<pre class="screen" id="obs_25_0309__screen543613403498"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0309__b1170133113446">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0309__b6170193114441">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0309__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Obtain the storage information about a bucket.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">GetBucketStorageInfoRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetBucketStorageInfoRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">GetBucketStorageInfoResponse</span> response = client.GetBucketStorageInfo(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Get bucket storageinfo response: {0}"</span>, response.StatusCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ObjectNumber: {0}"</span>, response.ObjectNumber);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Size: {0}"</span>, response.Size);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0309__note13749818135"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0309__ul1086684153714"><li id="obs_25_0309__li1086619411378">To handle the error codes possibly returned during the operation, see <a href="obs_25_1601.html">OBS Server-Side Error Codes</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

View File

@ -0,0 +1,66 @@
<a name="obs_25_0310"></a><a name="obs_25_0310"></a>
<h1 class="topictitle1">Setting or Obtaining a Bucket Quota</h1>
<div id="body1502764180079"><div class="section" id="obs_25_0310__section8517109534"><h4 class="sectiontitle">Setting a Bucket Quota</h4><p id="obs_25_0310__p25183913318">You can call <strong id="obs_25_0310__b842352706103511">ObsClient.SetBucketQuota</strong> to set the bucket quota. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0310__screen543613403498"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0310__b14750835144419">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0310__b1275016353441">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0310__b018213463919_1">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Set the bucket quota.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">SetBucketQuotaRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">SetBucketQuotaRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
StorageQuota = 0L,
};
<span style="color:#2B91AF;">SetBucketQuotaResponse</span> response = client.SetBucketQuota(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Set bucket quota response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0310__note132271983519"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0310__p244341033413">A bucket quota must be a non-negative integer expressed in bytes. The maximum value is <span style="color:#6A3E3E;">2</span><sup style="color:#6A3E3E;" id="obs_25_0310__sup628965522612">63</sup> - 1.</p>
</div></div>
</div>
<div class="section" id="obs_25_0310__section105838221315"><h4 class="sectiontitle">Obtaining the Bucket Quota</h4><p id="obs_25_0310__p1973015210235">You can call <strong id="obs_25_0310__b842352706103529">ObsClient.GetBucketQuota</strong> to obtain the bucket quota. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0310__screen4731152152311"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0310__b116204013440">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0310__b3164409441">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0310__b018213463919_3">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Obtain the bucket quota.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">GetBucketQuotaRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetBucketQuotaRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
};
<span style="color:#2B91AF;">GetBucketQuotaResponse</span> response = client.GetBucketQuota(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Get bucket quota response: {0}"</span>, response.StatusCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"StorageQuota: {0}"</span>, response.StorageQuota);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0300.html">Bucket Management</a></div>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
<a name="obs_25_0400"></a><a name="obs_25_0400"></a>
<h1 class="topictitle1">Object Upload</h1>
<div id="body1502764180079"></div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="obs_25_0401.html">Object Upload Overview</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0402.html">Performing a Streaming Upload</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0403.html">Performing a File-Based Upload</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0404.html">Performing an Asynchronous Upload</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0405.html">Obtaining Upload Progress</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0406.html">Creating a Folder</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0407.html">Setting Object Properties</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0408.html">Performing a Multipart Upload</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0409.html">Configuring Lifecycle Management</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0410.html">Performing an Appendable Upload</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0411.html">Performing a Multipart Copy</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0412.html">Performing a Resumable Upload</a></strong><br>
</li>
</ul>
</div>

View File

@ -0,0 +1,14 @@
<a name="obs_25_0401"></a><a name="obs_25_0401"></a>
<h1 class="topictitle1">Object Upload Overview</h1>
<div id="body1540263719370"><p id="obs_25_0401__p1876035911217">In OBS, objects are basic data units that users can perform operations on. OBS .NET SDK provides abundant APIs for object upload in the following methods:</p>
<ul id="obs_25_0401__ul476018591325"><li id="obs_25_0401__li197602599217"><a href="obs_25_0402.html">Performing a Streaming Upload</a></li><li id="obs_25_0401__li1076185914219"><a href="obs_25_0403.html">Performing a File-Based Upload</a></li><li id="obs_25_0401__li10761105914211"><a href="obs_25_0404.html">Performing an Asynchronous Upload</a></li><li id="obs_25_0401__li9761459724"><a href="obs_25_0408.html">Performing a Multipart Upload</a></li><li id="obs_25_0401__li1176116591129"><a href="obs_25_0410.html">Performing an Appendable Upload</a></li><li id="obs_25_0401__li29721113852"><a href="obs_25_0412.html">Performing a Resumable Upload</a></li></ul>
<p id="obs_25_0401__p078010233015">The SDK supports the upload of objects whose size ranges from 0 KB to 5 GB. If a file is smaller than 5 GB, streaming upload, appendable upload, and file-based upload are applicable. If the file is larger than 5 GB, multipart upload (whose part size is smaller than 5 GB) is suitable.</p>
<p id="obs_25_0401__p5761165910215">If you grant anonymous users the read permission for an object during the upload, anonymous users can access the object through a URL after the upload is complete. The object URL is in the format of <strong id="obs_25_0401__b102795455220">https://</strong><strong id="obs_25_0401__b152875416522"><em id="obs_25_0401__i428195425212">bucket name</em></strong><strong id="obs_25_0401__b02919547529">.</strong><strong id="obs_25_0401__b133095417524"><em id="obs_25_0401__i1529165419527">domain name</em></strong><strong id="obs_25_0401__b18303541527">/</strong><strong id="obs_25_0401__b13115543520"><em id="obs_25_0401__i18312547527">directory levels</em></strong><strong id="obs_25_0401__b20321754135213">/</strong><strong id="obs_25_0401__b933155411522"><em id="obs_25_0401__i10321854135218">object name</em></strong>. If the object resides in the root directory of the bucket, its URL does not contain directory levels.</p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,41 @@
<a name="obs_25_0402"></a><a name="obs_25_0402"></a>
<h1 class="topictitle1">Performing a Streaming Upload</h1>
<div id="body1502764180079"><p id="obs_25_0402__p8060118">Streaming upload uses <strong id="obs_25_0402__b842352706163353">System.IO.Stream</strong> as the data source of an object. You can call <strong id="obs_25_0402__b842352706103635">ObsClient.PutObject</strong> to upload the data streams to OBS. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0402__screen95103357215"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0402__b12635144513441">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0402__b663516453442">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0402__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Upload a stream.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">String</span> str = <span style="color:#A31515;">"Hello OBS"</span>;
<span style="color:#2B91AF;">Stream</span> stream = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">MemoryStream</span>(System.Text.<span style="color:#2B91AF;">Encoding</span>.Default.GetBytes(str));
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
InputStream = stream,
};
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.PutObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0402__note19917538583"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0402__ul1470322175911"><li id="obs_25_0402__li81552914584">To upload a large file, you are advised to use <a href="obs_25_0408.html">multipart upload</a>.</li><li id="obs_25_0402__li127041720591">The content to be uploaded cannot exceed 5 GB.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,41 @@
<a name="obs_25_0403"></a><a name="obs_25_0403"></a>
<h1 class="topictitle1">Performing a File-Based Upload</h1>
<div id="body1502764180079"><p id="obs_25_0403__p1817943419116">File-based upload uses local files as the data source of objects.</p>
<p id="obs_25_0403__p334833112196">This example uploads local file <strong id="obs_25_0403__b1930271165215">localfile</strong> to bucket <strong id="obs_25_0403__b1450677524">bucketname</strong> as object <strong id="obs_25_0403__b124151906528">objectname</strong>.</p>
<p id="obs_25_0403__p12258185071116">The example code is as follows:</p>
<pre class="screen" id="obs_25_0403__screen95103357215"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0403__b1693619501448">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0403__b493675064410">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an </span><span style="color:#008000;">ObsClient</span><span style="color:#008000;"> instance.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Upload a file.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>, <span style="color:#008000;">//</span><span style="color:#008000;">Name of the bucket for storing the file to be uploaded</span>
ObjectKey = <span style="color:#A31515;">"objectname"</span>, <span style="color:#008000;">//</span><span style="color:#008000;">Name of the file to be uploaded (The file name is the complete path of the file in the bucket, for example, </span><strong style="color:#008000;" id="obs_25_0403__b341303715294">folder/test.txt</strong><span style="color:#008000;">. The path does not contain the bucket name.)</span>
FilePath = <span style="color:#A31515;">"localfile"</span>,<span style="color:#008000;">//</span><span style="color:#008000;">Path of the local file to be uploaded, in which the file name must be specified</span>
};
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.PutObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0403__note1678610191508"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0403__ul163762681116"><li id="obs_25_0403__li1937326161112">The content to be uploaded cannot exceed 5 GB.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,50 @@
<a name="obs_25_0404"></a><a name="obs_25_0404"></a>
<h1 class="topictitle1">Performing an Asynchronous Upload</h1>
<div id="body1537414574216"><p id="obs_25_0404__p863132317716">You can call <strong id="obs_25_0404__b168375618175038">ObsClient.BeginPutObject</strong> and <strong id="obs_25_0404__b93214600475038">ObsClient.EndPutObject</strong> to upload an object asynchronously.</p>
<p id="obs_25_0404__p334833112196">This example asynchronously uploads local file <strong id="obs_25_0404__b163491865210">localfile</strong> to bucket <strong id="obs_25_0404__b3350136428">bucketname</strong> as object <strong id="obs_25_0404__b183501614213">objectname</strong>.</p>
<p id="obs_25_0404__p8060118">Sample code is as follows:</p>
<pre class="screen" id="obs_25_0404__screen95103357215"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0404__b1571965534415">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0404__b3719155515442">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
// Create an instance of <strong id="obs_25_0404__b56888498144351">ObsClient</strong>.
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
// Upload a file in asynchronous mode.
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
FilePath = "localfile",// Path of the local file to be uploaded. The file name must be specified.
};
client.BeginPutObject(request, <span style="color:#0000FF;">delegate</span>(<span style="color:#2B91AF;">IAsyncResult</span> ar){
<span style="color:#0000FF;"> try</span>
{
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.EndPutObject(ar);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;"> catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}
}, <span style="color:#0000FF;">null</span>);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Message: {0}"</span>, ex.Message);
}</pre>
<div class="note" id="obs_25_0404__note205061292811"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0404__ul69683561487"><li id="obs_25_0404__li20968145611813">For more information, see <a href="obs_25_0401.html">Object Upload Overview</a>.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,53 @@
<a name="obs_25_0405"></a><a name="obs_25_0405"></a>
<h1 class="topictitle1">Obtaining Upload Progress</h1>
<div id="body1532940692760"><p id="obs_25_0405__p552718121651">You can call <strong id="obs_25_0405__b106377883575044">PutObjectRequest.UploadProgress</strong> to register a <strong id="obs_25_0405__b71777020375044">System.EventHandler</strong> callback function to obtain upload progress.</p>
<p id="obs_25_0405__p15241129101914">This example uploads local file <strong id="obs_25_0405__b6251194311215">localfile</strong> to bucket <strong id="obs_25_0405__b11252143722">bucketname</strong> as object <strong id="obs_25_0405__b172524431529">objectname</strong> and uses <strong id="obs_25_0405__b1085165820219">System.EventHandler</strong> to monitor the upload progress.</p>
<p id="obs_25_0405__p2021612227247">The example code is as follows:</p>
<pre class="screen" id="obs_25_0405__screen15541152416311"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0405__b365719459">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0405__b146510174512">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
// Create an instance of <strong id="obs_25_0405__b018213463919">ObsClient</strong>.
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
// Upload a file.
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
FilePath = "localfile",// Path of the local file uploaded. The file name must be specified.
};
// Represent the progress by showing how many bytes have been uploaded.
request.ProgressType = <span style="color:#2B91AF;">ProgressTypeEnum</span>.ByBytes;
// Refresh the upload progress each time 1 MB data is uploaded.
request.ProgressInterval = 1024 * 1024;
// Register the upload progress callback function.
request.UploadProgress += <span style="color:#0000FF;">delegate</span>(<span style="color:#0000FF;">object</span> sender, <span style="color:#2B91AF;">TransferStatus</span> status){
// Obtain the average upload rate.
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"AverageSpeed: {0}"</span>, status.AverageSpeed / 1024 + <span style="color:#A31515;">"KB/S"</span>);
// Obtain the upload progress in percentage.
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"TransferPercentage: {0}"</span>, status.TransferPercentage);
};
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.PutObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0405__note1832461912196"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0405__ul133198233514"><li id="obs_25_0405__li113196238516">You can query the upload progress when uploading an object in streaming, file-based, asynchronous, resumable, or appendable mode, or uploading a part.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,38 @@
<a name="obs_25_0406"></a><a name="obs_25_0406"></a>
<h1 class="topictitle1">Creating a Folder</h1>
<div id="body1502764180079"><p id="obs_25_0406__p20682147153511">There is no folder concept in OBS. All elements in buckets are objects. To create a folder in OBS is essentially to create an object whose size is 0 and whose name ends with a slash (/). Such objects have no difference from other objects and can be downloaded and deleted, except that they are displayed as folders in OBS Console.</p>
<pre class="screen" id="obs_25_0406__screen95103357215"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0406__b16193020115315">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0406__b51931120175316">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0406__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Create a folder.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"dir/"</span>,
};
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.PutObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0406__note769151916367"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0406__ul1065574283614"><li id="obs_25_0406__li76551342153612">To create a folder in OBS is to create an object whose size is 0 and whose name ends with a slash (/), in essential.</li><li id="obs_25_0406__li065512429362">To create a multi-level folder, you only need to create the folder with the last level. For example, if you want to create a folder named <strong id="obs_25_0406__b842352706103949">src1/src2/src3/</strong>, create it directly, no matter whether the <strong id="obs_25_0406__b842352706104130">src1/</strong> and <strong id="obs_25_0406__b842352706104134">src1/src2/</strong> folders exist.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
<a name="obs_25_0409"></a><a name="obs_25_0409"></a>
<h1 class="topictitle1">Configuring Lifecycle Management</h1>
<div id="body1530858968001"><p id="obs_25_0409__p1654155717523">When uploading an object or initializing a multipart upload, you can directly set the expiration time for the object. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0409__screen124693539417"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0409__b208981145134519">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0409__b48981345134514">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
// Create an instance of <strong id="obs_25_0409__b018213463919">ObsClient</strong>.
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">PutObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">PutObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
FilePath = "localfile",// Path of the local file uploaded. The file name must be specified.
Expires = 30 // When uploading an object, set the object to expire after 30 days.
};
<span style="color:#2B91AF;">PutObjectResponse</span> response = client.PutObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"put object response: {0}"</span>, response.StatusCode);
<span style="color:#2B91AF;"> InitiateMultipartUploadRequest</span> initiateRequest = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">InitiateMultipartUploadRequest</span>
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
// When initializing a multipart upload, set the object to expire 60 days after combination.
Expires = 60
};
<span style="color:#2B91AF;">InitiateMultipartUploadResponse</span> initResponse = client.InitiateMultipartUpload(initiateRequest);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"InitiateMultipartUpload status: {0}"</span>, initResponse.StatusCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"InitiateMultipartUpload UploadId: {0}"</span>, initResponse.UploadId);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0409__note15367192017477"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0409__ul118051338115011"><li id="obs_25_0409__li12805538145013">The previous mode specifies the time duration in days after which an object will expire. The OBS server automatically clears expired objects.</li><li id="obs_25_0409__li111810423504">The object expiration time set in the preceding method takes precedence over the bucket lifecycle rule.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,49 @@
<a name="obs_25_0410"></a><a name="obs_25_0410"></a>
<h1 class="topictitle1">Performing an Appendable Upload</h1>
<div id="body1528522215568"><p class="msonormal" id="obs_25_0410__p4169125">Appendable upload allows you to upload an object in appendable mode and then append data to the object. You can call <strong id="obs_25_0410__b503216878113145">ObsClient.AppendObject</strong> to perform an appendable upload. Sample code is as follows:</p>
<pre class="screen" id="obs_25_0410__screen17780822688"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0410__b16151950204511">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0410__b7151850174514">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0410__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#0000FF;">try</span>
{
<span style="color:#008000;">// Upload an object in appendable mode.</span>
<span style="color:#2B91AF;">AppendObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">AppendObjectRequest</span>();
request.BucketName = <span style="color:#A31515;">"bucketname"</span>;
request.ObjectKey = <span style="color:#A31515;">"objectkey"</span>;
request.InputStream = <span style="color:#0000FF;">new</span> MemoryStream(Encoding.UTF8.GetBytes(<span style="color:#A31515;">"Hello OBS"</span>));
<span style="color:#2B91AF;">AppendObjectResponse</span> response = client.AppendObject(request);
<span style="color:#008000;">// Append data to the object.</span>
request.Position = response.NextPosition;
request.InputStream = <span style="color:#0000FF;">new</span> MemoryStream(Encoding.UTF8.GetBytes(<span style="color:#A31515;">"Hello OBS Again"</span>));
response = client.AppendObject(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"NextPosition:{0}"</span>, response.NextPosition);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ETag:{0}"</span>, response.ETag);
<span style="color:#008000;">// Use the API for obtaining object properties to get the start position for next appending.</span>
<span style="color:#2B91AF;">GetObjectMetadataResponse </span>metadataResponse = client.GetObjectMetadata(<span style="color:#A31515;">"bucketname"</span>, <span style="color:#A31515;">"objectkey"</span>);
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"NextPosition from metadata:{0}"</span>, metadataResponse.NextPosition);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException </span>ex)
{
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0410__note52127319717"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="obs_25_0410__ul3545193812718"><li class="litext" id="obs_25_0410__li1554383811717">Objects uploaded using <strong id="obs_25_0410__b842352706104019">ObsClient.PutObject</strong>, referred to as normal objects, can overwrite objects uploaded using <strong id="obs_25_0410__b842352706104024">ObsClient.AppendObject</strong>, referred to as appendable objects. Data cannot be appended to an appendable object once the object has been overwritten by a normal object.</li><li class="litext" id="obs_25_0410__li25458387716">When you upload an object for the first time in append mode, an exception will be reported (HTTP status code <strong id="obs_25_0410__b163762582512">409</strong>) if an object of the same name exists.</li><li class="litext" id="obs_25_0410__li1154515389717">The ETag returned for each append upload is the ETag for the uploaded content, rather than that of the whole object.</li><li class="litext" id="obs_25_0410__li5545133819715">Data appended each time can be up to 5 GB, and 10000 times of appendable uploads can be performed on a single object.</li><li id="obs_25_0410__li2597203811118">After an appendable upload is successful, you can use <strong id="obs_25_0410__b84235270611913">AppendObjectResponse.NextPosition</strong> or call <strong id="obs_25_0410__b842352706105222">ObsClient.GetObjectMetadata</strong> to get the start position for next appending.</li></ul>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

View File

@ -0,0 +1,40 @@
<a name="obs_25_0411"></a><a name="obs_25_0411"></a>
<h1 class="topictitle1">Performing a Multipart Copy</h1>
<div id="body1502885594830"><p id="obs_25_0411__p186924473251">As a special case of multipart upload, multipart copy implements multipart upload by copying the whole or part of an object in a bucket. You can call <strong id="obs_25_0411__b83241925974957">ObsClient.CopyPart</strong> to copy parts.</p>
<p id="obs_25_0411__p913054415711">This example copies object <strong id="obs_25_0411__b1157781311146">sourceobjectname</strong> from bucket <strong id="obs_25_0411__b313631621417">sourcebucketname</strong> to bucket <strong id="obs_25_0411__b18215113591415">destbucketname</strong> as object <strong id="obs_25_0411__b288444111416">destobjectname</strong>.</p>
<p id="obs_25_0411__p181993815715">The example code is as follows:</p>
<pre class="screen" id="obs_25_0411__screen132667341917"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0411__b955585514451">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0411__b4555135514519">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0411__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Copy parts.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">CopyPartRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">CopyPartRequest</span>();
request.BucketName = <span style="color:#A31515;">"bucketname"</span>;
request.ObjectKey = <span style="color:#A31515;">"objectname"</span>;
request.UploadId = <span style="color:#A31515;">"uploadId"</span>;
request.PartNumber = 1;
request.SourceBucketName = <span style="color:#A31515;">"sourcebucketname"</span>;
request.SourceObjectKey = <span style="color:#A31515;">"sourceobjectname"</span>;
<span style="color:#2B91AF;">CopyPartResponse</span> response = client.CopyPart(request);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Copy part response: {0}"</span>, response.StatusCode);
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
} </pre>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0400.html">Object Upload</a></div>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
<a name="obs_25_0500"></a><a name="obs_25_0500"></a>
<h1 class="topictitle1">Object Download</h1>
<div id="body1502764180079"></div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="obs_25_0501.html">Object Download Overview</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0502.html">Performing a Streaming Download</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0503.html">Performing a Partial Download</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0504.html">Performing an Asynchronous Download</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0505.html">Obtaining Download Progress</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0506.html">Performing a Conditioned Download</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0507.html">Rewriting Response Headers</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0508.html">Obtaining Custom Metadata</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0509.html">Downloading a Cold Object</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="obs_25_0510.html">Performing a Resumable Download</a></strong><br>
</li>
</ul>
</div>

View File

@ -0,0 +1,13 @@
<a name="obs_25_0501"></a><a name="obs_25_0501"></a>
<h1 class="topictitle1">Object Download Overview</h1>
<div id="body1540263719370"><p id="obs_25_0501__p12357142314717">OBS .NET SDK provides abundant APIs for downloading objects in the following modes:</p>
<ul id="obs_25_0501__ul53578237719"><li id="obs_25_0501__li12357162312717"><a href="obs_25_0502.html">Performing a Streaming Download</a></li><li id="obs_25_0501__li63572231374"><a href="obs_25_0503.html">Performing a Partial Download</a></li><li id="obs_25_0501__li6476663812"><a href="obs_25_0504.html">Performing an Asynchronous Download</a></li><li id="obs_25_0501__li14376151916812"><a href="obs_25_0506.html">Performing a Conditioned Download</a></li><li id="obs_25_0501__li93571723879"><a href="obs_25_0510.html">Performing a Resumable Download</a></li></ul>
<p id="obs_25_0501__p14357823378">You can call <strong id="obs_25_0501__b842352706155639">ObsClient.GetObject</strong> to download an object.</p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0500.html">Object Download</a></div>
</div>
</div>

View File

@ -0,0 +1,48 @@
<a name="obs_25_0502"></a><a name="obs_25_0502"></a>
<h1 class="topictitle1">Performing a Streaming Download</h1>
<div id="body1502764180080"><p id="obs_25_0502__p8060118">Sample code:</p>
<pre class="screen" id="obs_25_0502__screen19344497154448"><span style="color:#008000;">// Initialize configuration parameters.</span>
<span style="color:#2B91AF;">ObsConfig</span> config = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsConfig</span>();
config.Endpoint = <span style="color:#A31515;">"https://your-endpoint"</span>;
//<span style="color:#008000;"> Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables </span><strong style="color:#008000;" id="obs_25_0502__b1756124311538">AccessKeyID</strong><span style="color:#008000;"> and </span><strong style="color:#008000;" id="obs_25_0502__b10756124313534">SecretAccessKey</strong><span style="color:#008000;">.</span>
// Obtain an AK/SK pair on the management console.
<span style="color:#0000FF;">string</span> accessKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">AccessKeyID</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#0000FF;">string</span> secretKey= Environment.GetEnvironmentVariable(<span style="color:#800000;">"</span><span style="color:#800000;">SecretAccessKey</span><span style="color:#800000;">"</span>, EnvironmentVariableTarget.Machine);
<span style="color:#008000;">// </span><span style="color:#008000;">Create an instance of </span><strong style="color:#008000;" id="obs_25_0502__b018213463919">ObsClient</strong><span style="color:#008000;">.</span>
<span style="color:#2B91AF;">ObsClient</span> client = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">ObsClient</span>(accessKey, secretKey, config);
<span style="color:#008000;">// </span><span style="color:#008000;">Download an object.</span>
<span style="color:#0000FF;">try</span>
{
<span style="color:#2B91AF;">GetObjectRequest</span> request = <span style="color:#0000FF;">new</span> <span style="color:#2B91AF;">GetObjectRequest</span>()
{
BucketName = <span style="color:#A31515;">"bucketname"</span>,
ObjectKey = <span style="color:#A31515;">"objectname"</span>,
};
<span style="color:#0000FF;">using</span> (<span style="color:#2B91AF;">GetObjectResponse</span> response = client.GetObject(request))
{
<span style="color:#0000FF;">string</span> dest = <span style="color:#A31515;">"savepath"</span>;
<span style="color:#0000FF;">if</span> (!<span style="color:#2B91AF;">File</span>.Exists(dest))
{
<span style="color:#008000;"> // </span><span style="color:#008000;">Write the data streams into the file.</span>
response.WriteResponseStreamToFile(dest);
}
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"Get object response: {0}"</span>, response.StatusCode);
}
}
<span style="color:#0000FF;">catch</span> (<span style="color:#2B91AF;">ObsException</span> ex)
{
<span style="color:#2B91AF;"> Console</span>.WriteLine(<span style="color:#A31515;">"ErrorCode: {0}"</span>, ex.ErrorCode);
<span style="color:#2B91AF;">Console</span>.WriteLine(<span style="color:#A31515;">"ErrorMessage: {0}"</span>, ex.ErrorMessage);
}</pre>
<div class="note" id="obs_25_0502__note12588114812143"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="obs_25_0502__p16676214104519"><strong id="obs_25_0502__b84235270611258">GetObjectResponse.OutputStream</strong> (<strong id="obs_25_0502__b84235270611715">System.IO.Stream</strong> type) is the response stream in <strong id="obs_25_0502__b8423527061132">GetObjectResponse</strong>. You can obtain the object content to a local file or memory via <strong id="obs_25_0502__b84235270611419">GetObjectResponse.OutputStream</strong>. Alternatively, you can call <strong id="obs_25_0502__b84235270611456">GetObjectResponse.WriteResponseStreamToFile</strong> provided by OBS .NET SDK to download the object content to a local file.</p>
</div></div>
<div class="notice" id="obs_25_0502__note104881352171417"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="obs_25_0502__p17339227171911">Object response streams obtained by <strong id="obs_25_0502__b842352706114057">GetObjectResponse.OutputStream</strong> must be closed explicitly using a <strong id="obs_25_0502__b175932188253">GetObjectResponse.OutputStream.Close()</strong> call. Otherwise, resource leakage may occur.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_25_0500.html">Object Download</a></div>
</div>
</div>

Some files were not shown because too many files have changed in this diff Show More