- To use Alibaba Cloud SDK for .Net, you must have an Alibaba Cloud account as well as an
AccessKey ID
and 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.
Use .Net CLI ( Recommand )
dotnet add package AlibabaCloud.SDK.ImageSearch
Use Package Manager
Install-Package AlibabaCloud.SDK.ImageSearch
The following code example shows the four main steps to use Alibaba Cloud SDK for .Net :
-
Create and initialize a
Client
instance. -
Create and set up parameters
RuntimeObject
instance. -
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);
}
}
}