44using System . IO ;
55using System . Linq ;
66using System . Net . Http ;
7+ using System . Threading ;
78using System . Threading . Tasks ;
89using System . Web ;
910using Newtonsoft . Json ;
@@ -172,14 +173,14 @@ await Helpers.MakeRequest<List<FileObject>>(HttpMethod.Post, $"{Url}/object/list
172173 /// <param name="inferContentType"></param>
173174 /// <returns></returns>
174175 public async Task < string > Upload ( string localFilePath , string supabasePath , FileOptions ? options = null ,
175- EventHandler < float > ? onProgress = null , bool inferContentType = true )
176+ EventHandler < float > ? onProgress = null , bool inferContentType = true , CancellationToken cancellationToken = default )
176177 {
177178 options ??= new FileOptions ( ) ;
178179
179180 if ( inferContentType )
180181 options . ContentType = MimeMapping . MimeUtility . GetMimeMapping ( localFilePath ) ;
181182
182- var result = await UploadOrUpdate ( localFilePath , supabasePath , options , onProgress ) ;
183+ var result = await UploadOrUpdate ( localFilePath , supabasePath , options , onProgress , cancellationToken ) ;
183184 return result ;
184185 }
185186
@@ -193,14 +194,14 @@ public async Task<string> Upload(string localFilePath, string supabasePath, File
193194 /// <param name="inferContentType"></param>
194195 /// <returns></returns>
195196 public async Task < string > Upload ( byte [ ] data , string supabasePath , FileOptions ? options = null ,
196- EventHandler < float > ? onProgress = null , bool inferContentType = true )
197+ EventHandler < float > ? onProgress = null , bool inferContentType = true , CancellationToken cancellationToken = default )
197198 {
198199 options ??= new FileOptions ( ) ;
199200
200201 if ( inferContentType )
201202 options . ContentType = MimeMapping . MimeUtility . GetMimeMapping ( supabasePath ) ;
202203
203- var result = await UploadOrUpdate ( data , supabasePath , options , onProgress ) ;
204+ var result = await UploadOrUpdate ( data , supabasePath , options , onProgress , cancellationToken ) ;
204205 return result ;
205206 }
206207
@@ -288,10 +289,10 @@ public async Task<string> UploadToSignedUrl(byte[] data, UploadSignedUrl signedU
288289 /// <param name="onProgress"></param>
289290 /// <returns></returns>
290291 public Task < string > Update ( string localFilePath , string supabasePath , FileOptions ? options = null ,
291- EventHandler < float > ? onProgress = null )
292+ EventHandler < float > ? onProgress = null , CancellationToken cancellationToken = default )
292293 {
293294 options ??= new FileOptions ( ) ;
294- return UploadOrUpdate ( localFilePath , supabasePath , options , onProgress ) ;
295+ return UploadOrUpdate ( localFilePath , supabasePath , options , onProgress , cancellationToken ) ;
295296 }
296297
297298 /// <summary>
@@ -303,10 +304,10 @@ public Task<string> Update(string localFilePath, string supabasePath, FileOption
303304 /// <param name="onProgress"></param>
304305 /// <returns></returns>
305306 public Task < string > Update ( byte [ ] data , string supabasePath , FileOptions ? options = null ,
306- EventHandler < float > ? onProgress = null )
307+ EventHandler < float > ? onProgress = null , CancellationToken cancellationToken = default )
307308 {
308309 options ??= new FileOptions ( ) ;
309- return UploadOrUpdate ( data , supabasePath , options , onProgress ) ;
310+ return UploadOrUpdate ( data , supabasePath , options , onProgress , cancellationToken ) ;
310311 }
311312
312313 /// <summary>
@@ -480,7 +481,7 @@ public async Task<UploadSignedUrl> CreateUploadSignedUrl(string supabasePath)
480481 }
481482
482483 private async Task < string > UploadOrUpdate ( string localPath , string supabasePath , FileOptions options ,
483- EventHandler < float > ? onProgress = null )
484+ EventHandler < float > ? onProgress = null , CancellationToken cancellationToken = default )
484485 {
485486 Uri uri = new Uri ( $ "{ Url } /object/{ GetFinalPath ( supabasePath ) } ") ;
486487
@@ -506,7 +507,7 @@ private async Task<string> UploadOrUpdate(string localPath, string supabasePath,
506507 if ( onProgress != null )
507508 progress . ProgressChanged += onProgress ;
508509
509- await Helpers . HttpUploadClient ! . UploadFileAsync ( uri , localPath , headers , progress ) ;
510+ await Helpers . HttpUploadClient ! . UploadFileAsync ( uri , localPath , headers , progress , cancellationToken ) ;
510511
511512 return GetFinalPath ( supabasePath ) ;
512513 }
@@ -520,7 +521,7 @@ private static string ParseMetadata(Dictionary<string, string> metadata)
520521 }
521522
522523 private async Task < string > UploadOrUpdate ( byte [ ] data , string supabasePath , FileOptions options ,
523- EventHandler < float > ? onProgress = null )
524+ EventHandler < float > ? onProgress = null , CancellationToken cancellationToken = default )
524525 {
525526 Uri uri = new Uri ( $ "{ Url } /object/{ GetFinalPath ( supabasePath ) } ") ;
526527
@@ -546,7 +547,7 @@ private async Task<string> UploadOrUpdate(byte[] data, string supabasePath, File
546547 if ( onProgress != null )
547548 progress . ProgressChanged += onProgress ;
548549
549- await Helpers . HttpUploadClient ! . UploadBytesAsync ( uri , data , headers , progress ) ;
550+ await Helpers . HttpUploadClient ! . UploadBytesAsync ( uri , data , headers , progress , cancellationToken ) ;
550551
551552 return GetFinalPath ( supabasePath ) ;
552553 }
0 commit comments