11using System ;
22using System . Collections . Generic ;
3+ using System . Collections . Specialized ;
34using System . IO ;
45using System . Linq ;
56using System . Net . Http ;
@@ -41,15 +42,25 @@ public StorageFileApi(string url, Dictionary<string, string>? headers = null, st
4142 /// </summary>
4243 /// <param name="path"></param>
4344 /// <param name="transformOptions"></param>
45+ /// <param name="downloadOptions"></param>
4446 /// <returns></returns>
45- public string GetPublicUrl ( string path , TransformOptions ? transformOptions )
47+ public string GetPublicUrl ( string path , TransformOptions ? transformOptions , DownloadOptions ? downloadOptions = null )
4648 {
49+ var queryParams = HttpUtility . ParseQueryString ( string . Empty ) ;
50+
51+ if ( downloadOptions != null )
52+ queryParams . Add ( downloadOptions . ToQueryCollection ( ) ) ;
53+
4754 if ( transformOptions == null )
48- return $ "{ Url } /object/public/{ GetFinalPath ( path ) } ";
55+ {
56+ var queryParamsString = queryParams . ToString ( ) ;
57+ return $ "{ Url } /object/public/{ GetFinalPath ( path ) } ?{ queryParamsString } ";
58+ }
4959
60+ queryParams . Add ( transformOptions . ToQueryCollection ( ) ) ;
5061 var builder = new UriBuilder ( $ "{ Url } /render/image/public/{ GetFinalPath ( path ) } ")
5162 {
52- Query = transformOptions . ToQueryCollection ( ) . ToString ( )
63+ Query = queryParams . ToString ( )
5364 } ;
5465
5566 return builder . ToString ( ) ;
@@ -61,8 +72,9 @@ public string GetPublicUrl(string path, TransformOptions? transformOptions)
6172 /// <param name="path">The file path to be downloaded, including the current file name. For example `folder/image.png`.</param>
6273 /// <param name="expiresIn">The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.</param>
6374 /// <param name="transformOptions"></param>
75+ /// <param name="downloadOptions"></param>
6476 /// <returns></returns>
65- public async Task < string > CreateSignedUrl ( string path , int expiresIn , TransformOptions ? transformOptions = null )
77+ public async Task < string > CreateSignedUrl ( string path , int expiresIn , TransformOptions ? transformOptions = null , DownloadOptions ? downloadOptions = null )
6678 {
6779 var body = new Dictionary < string , object ? > { { "expiresIn" , expiresIn } } ;
6880 var url = $ "{ Url } /object/sign/{ GetFinalPath ( path ) } ";
@@ -79,22 +91,26 @@ public async Task<string> CreateSignedUrl(string path, int expiresIn, TransformO
7991 if ( response == null || string . IsNullOrEmpty ( response . SignedUrl ) )
8092 throw new SupabaseStorageException (
8193 $ "Signed Url for { path } returned empty, do you have permission?") ;
94+
95+ var downloadQueryParams = downloadOptions ? . ToQueryCollection ( ) . ToString ( ) ;
8296
83- return $ "{ Url } { response ? . SignedUrl } ";
97+ return $ "{ Url } { response . SignedUrl } ? { downloadQueryParams } ";
8498 }
8599
86100 /// <summary>
87101 /// Create signed URLs to download files without requiring permissions. These URLs can be valid for a set number of seconds.
88102 /// </summary>
89103 /// <param name="paths">paths The file paths to be downloaded, including the current file names. For example [`folder/image.png`, 'folder2/image2.png'].</param>
90104 /// <param name="expiresIn">The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.</param>
105+ /// <param name="downloadOptions"></param>
91106 /// <returns></returns>
92- public async Task < List < CreateSignedUrlsResponse > ? > CreateSignedUrls ( List < string > paths , int expiresIn )
107+ public async Task < List < CreateSignedUrlsResponse > ? > CreateSignedUrls ( List < string > paths , int expiresIn , DownloadOptions ? downloadOptions = null )
93108 {
94109 var body = new Dictionary < string , object > { { "expiresIn" , expiresIn } , { "paths" , paths } } ;
95110 var response = await Helpers . MakeRequest < List < CreateSignedUrlsResponse > > ( HttpMethod . Post ,
96111 $ "{ Url } /object/sign/{ BucketId } ", body , Headers ) ;
97112
113+ var downloadQueryParams = downloadOptions ? . ToQueryCollection ( ) . ToString ( ) ;
98114 if ( response != null )
99115 {
100116 foreach ( var item in response )
@@ -103,7 +119,7 @@ public async Task<string> CreateSignedUrl(string path, int expiresIn, TransformO
103119 throw new SupabaseStorageException (
104120 $ "Signed Url for { item . Path } returned empty, do you have permission?") ;
105121
106- item . SignedUrl = $ "{ Url } { item . SignedUrl } ";
122+ item . SignedUrl = $ "{ Url } { item . SignedUrl } ? { downloadQueryParams } ";
107123 }
108124 }
109125
0 commit comments