0-Examples-EN.md
June 18, 2020 · View on GitHub
Requirements
- To use Alibaba Cloud SDK for .Net, you must have an Alibaba Cloud account as well as an
AccessKey IDand anAccessKey Secret. Create and view your AccessKey on the RAM console or contact your system administrator. - To use the Alibaba Cloud SDK for .Net to access the APIs of a product, you must first activate the product on the Alibaba Cloud console if required.
- The Alibaba Cloud .Net SDK requires net45 or netstandard2.0.
Installation Example For ImageSearch
Use .Net CLI ( Recommand )
dotnet add package AlibabaCloud.SDK.ImageSearch
Use Package Manager
Install-Package AlibabaCloud.SDK.ImageSearch
Quick Examples For ImageSearch
The following code example shows the four main steps to use Alibaba Cloud SDK for .Net :
-
Create and initialize a
Clientinstance. -
Create and set up parameters
RuntimeObjectinstance. -
Create an API request and set parameters.
-
Initiate the request and handle the response or exceptions.
using System.IO;
using AlibabaCloud.ImageSearch;
using AlibabaCloud.ImageSearch.Models;
using AlibabaCloud.TeaUtil.Models;
namespace Demo
{
class TeaDemo
{
static void Main(string[] args)
{
// 1 Create and initialize a Client instance.
Config config = new Config();
config.AccessKeyId = "your accessKeyId";
config.AccessKeySecret = "your accessKeySecret";
config.Endpoint = "your endpoint";
config.RegionId = "cn-shanghai";
config.Type = "access_key";
Client client = new Client(config);
// 2 Create and set up parameters RuntimeObject instance.
RuntimeOptions runtimeObject = new RuntimeOptions();
// 3 Create an API request and set parameters.
AddImageAdvanceRequest request = new AddImageAdvanceRequest();
request.PicName = "picName";
request.ProductId = "productId";
request.InstanceName = "instanceName";
FileStream fs = File.OpenRead("your fileName");
request.PicContentObject = fs;
// 4 Initiate the request and handle the response or exceptions.
AddImageResponse response = client.AddImageAdvance(request, runtimeObject);
}
}
}