public string Upload(string fileName, Stream stream) { try { GetOssStsTokenRequest getOssStsTokenRequest = new GetOssStsTokenRequest(); var getOssStsTokenResponse = client.GetOssStsToken(getOssStsTokenRequest); string akKey = getOssStsTokenResponse.Data.AccessKeyId; string akSec = getOssStsTokenResponse.Data.AccessKeySecret; string token = getOssStsTokenResponse.Data.SecurityToken; string key = accessKeyId + "/" + Guid.NewGuid().ToString() + fileName; OSS.Models.Config ossConfig = new OSS.Models.Config(); ossConfig.AccessKeyId = akKey; ossConfig.AccessKeySecret = akSec; ossConfig.SecurityToken = token; ossConfig.Endpoint = "oss-cn-shanghai.aliyuncs.com"; ossConfig.Type = "sts"; OSS.Client ossClient = new OSS.Client(ossConfig); OSS.Models.PutObjectRequest request = new OSS.Models.PutObjectRequest(); request.BucketName = "viapi-customer-temp"; request.Body = stream; request.ObjectName = key; var ossRes = ossClient.PutObject(request, new OSSUtil.Models.RuntimeOptions()); return("http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/" + key); } finally { if (stream != null) { stream.Close(); } } }
public async Task <GetOssStsTokenResponse> GetOssStsTokenAsync(GetOssStsTokenRequest request) { AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); return(await GetOssStsTokenExAsync(request, runtime)); }
public GetOssStsTokenResponse GetOssStsToken(GetOssStsTokenRequest request) { AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); return(GetOssStsTokenEx(request, runtime)); }
public async Task <GetOssStsTokenResponse> GetOssStsTokenExAsync(GetOssStsTokenRequest request, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { AlibabaCloud.TeaUtil.Common.ValidateModel(request); return(TeaModel.ToObject <GetOssStsTokenResponse>(await DoRequestAsync("GetOssStsToken", "HTTPS", "POST", "2020-04-01", "AK", null, request.ToMap(), runtime))); }