@@ -236,19 +236,26 @@ public async Task<OssResult<GetObjectMetaResult>> GetObjectMetaAsync(BucketInfo
236236 /// <summary>
237237 /// 获取文件的下载链接
238238 /// </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>
241243 /// <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 )
243245 {
244- long seconds = ( DateTime . UtcNow . Ticks - 621355968000000000 ) / 10000000 ;
246+ long seconds = ( DateTime . UtcNow . AddSeconds ( expireSeconds ) . Ticks - 621355968000000000 ) / 10000000 ;
245247
246248 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+ }
247253
248254 string sign = ServiceSignature . Create ( ) . ComputeSignature (
249- _requestContext . OssCredential . AccessKeyId , toSign ) ;
255+ _requestContext . OssCredential . AccessKeySecret , toSign ) ;
250256
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 ) } ";
252259
253260 return url ;
254261 }
0 commit comments