1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Collections . Specialized ;
3
4
using System . IO ;
4
5
using System . Linq ;
5
6
using System . Net . Http ;
@@ -41,15 +42,25 @@ public StorageFileApi(string url, Dictionary<string, string>? headers = null, st
41
42
/// </summary>
42
43
/// <param name="path"></param>
43
44
/// <param name="transformOptions"></param>
45
+ /// <param name="downloadOptions"></param>
44
46
/// <returns></returns>
45
- public string GetPublicUrl ( string path , TransformOptions ? transformOptions )
47
+ public string GetPublicUrl ( string path , TransformOptions ? transformOptions , DownloadOptions ? downloadOptions = null )
46
48
{
49
+ var queryParams = HttpUtility . ParseQueryString ( string . Empty ) ;
50
+
51
+ if ( downloadOptions != null )
52
+ queryParams . Add ( downloadOptions . ToQueryCollection ( ) ) ;
53
+
47
54
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
+ }
49
59
60
+ queryParams . Add ( transformOptions . ToQueryCollection ( ) ) ;
50
61
var builder = new UriBuilder ( $ "{ Url } /render/image/public/{ GetFinalPath ( path ) } ")
51
62
{
52
- Query = transformOptions . ToQueryCollection ( ) . ToString ( )
63
+ Query = queryParams . ToString ( )
53
64
} ;
54
65
55
66
return builder . ToString ( ) ;
@@ -61,8 +72,9 @@ public string GetPublicUrl(string path, TransformOptions? transformOptions)
61
72
/// <param name="path">The file path to be downloaded, including the current file name. For example `folder/image.png`.</param>
62
73
/// <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>
63
74
/// <param name="transformOptions"></param>
75
+ /// <param name="downloadOptions"></param>
64
76
/// <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 )
66
78
{
67
79
var body = new Dictionary < string , object ? > { { "expiresIn" , expiresIn } } ;
68
80
var url = $ "{ Url } /object/sign/{ GetFinalPath ( path ) } ";
@@ -79,22 +91,26 @@ public async Task<string> CreateSignedUrl(string path, int expiresIn, TransformO
79
91
if ( response == null || string . IsNullOrEmpty ( response . SignedUrl ) )
80
92
throw new SupabaseStorageException (
81
93
$ "Signed Url for { path } returned empty, do you have permission?") ;
94
+
95
+ var downloadQueryParams = downloadOptions ? . ToQueryCollection ( ) . ToString ( ) ;
82
96
83
- return $ "{ Url } { response ? . SignedUrl } ";
97
+ return $ "{ Url } { response . SignedUrl } ? { downloadQueryParams } ";
84
98
}
85
99
86
100
/// <summary>
87
101
/// Create signed URLs to download files without requiring permissions. These URLs can be valid for a set number of seconds.
88
102
/// </summary>
89
103
/// <param name="paths">paths The file paths to be downloaded, including the current file names. For example [`folder/image.png`, 'folder2/image2.png'].</param>
90
104
/// <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>
91
106
/// <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 )
93
108
{
94
109
var body = new Dictionary < string , object > { { "expiresIn" , expiresIn } , { "paths" , paths } } ;
95
110
var response = await Helpers . MakeRequest < List < CreateSignedUrlsResponse > > ( HttpMethod . Post ,
96
111
$ "{ Url } /object/sign/{ BucketId } ", body , Headers ) ;
97
112
113
+ var downloadQueryParams = downloadOptions ? . ToQueryCollection ( ) . ToString ( ) ;
98
114
if ( response != null )
99
115
{
100
116
foreach ( var item in response )
@@ -103,7 +119,7 @@ public async Task<string> CreateSignedUrl(string path, int expiresIn, TransformO
103
119
throw new SupabaseStorageException (
104
120
$ "Signed Url for { item . Path } returned empty, do you have permission?") ;
105
121
106
- item . SignedUrl = $ "{ Url } { item . SignedUrl } ";
122
+ item . SignedUrl = $ "{ Url } { item . SignedUrl } ? { downloadQueryParams } ";
107
123
}
108
124
}
109
125
0 commit comments