@@ -236,19 +236,26 @@ public async Task<OssResult<GetObjectMetaResult>> GetObjectMetaAsync(BucketInfo
236
236
/// <summary>
237
237
/// 获取文件的下载链接
238
238
/// </summary>
239
- /// <param name="storeKey"></param>
240
- /// <param name="expireSeconds"></param>
239
+ /// <param name="bucket">bucket信息</param>
240
+ /// <param name="storeKey">文件存储key</param>
241
+ /// <param name="expireSeconds">签名超时时间秒数</param>
242
+ /// <param name="imgStyle">阿里云图片处理样式</param>
241
243
/// <returns></returns>
242
- public string GetFileDownloadLink ( BucketInfo bucket , string storeKey , int expireSeconds )
244
+ public string GetFileDownloadLink ( BucketInfo bucket , string storeKey , int expireSeconds , string imgStyle = null )
243
245
{
244
- long seconds = ( DateTime . UtcNow . Ticks - 621355968000000000 ) / 10000000 ;
246
+ long seconds = ( DateTime . UtcNow . AddSeconds ( expireSeconds ) . Ticks - 621355968000000000 ) / 10000000 ;
245
247
246
248
string toSign = String . Format ( "GET\n \n \n {0}\n /{1}/{2}" , seconds , bucket . BucketName , storeKey ) ;
249
+ if ( ! String . IsNullOrEmpty ( imgStyle ) )
250
+ {
251
+ toSign += $ "?x-oss-process=style/{ imgStyle } ";
252
+ }
247
253
248
254
string sign = ServiceSignature . Create ( ) . ComputeSignature (
249
- _requestContext . OssCredential . AccessKeyId , toSign ) ;
255
+ _requestContext . OssCredential . AccessKeySecret , toSign ) ;
250
256
251
- string url = $ "{ bucket . BucketUri } /{ storeKey } ?OSSAccessKeyId={ _requestContext . OssCredential . AccessKeyId } &Expires={ seconds } &Signature={ WebUtility . UrlEncode ( sign ) } ";
257
+ string styleSegment = String . IsNullOrEmpty ( imgStyle ) ? String . Empty : $ "x-oss-process=style/{ imgStyle } &";
258
+ string url = $ "{ bucket . BucketUri } { storeKey } ?{ styleSegment } OSSAccessKeyId={ _requestContext . OssCredential . AccessKeyId } &Expires={ seconds } &Signature={ WebUtility . UrlEncode ( sign ) } ";
252
259
253
260
return url ;
254
261
}
0 commit comments