Skip to content

Commit d4e2519

Browse files
committed
feat: implement method find
1 parent db1c592 commit d4e2519

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

Storage/FileObjectV2.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace Supabase.Storage
6+
{
7+
public class FileObjectV2
8+
{
9+
10+
[JsonProperty("id")]
11+
public string Id { get; set; }
12+
13+
[JsonProperty("version")]
14+
public string Version { get; set; }
15+
16+
[JsonProperty("name")]
17+
public string? Name { get; set; }
18+
19+
[JsonProperty("bucket_id")]
20+
public string? BucketId { get; set; }
21+
22+
[JsonProperty("updated_at")]
23+
public DateTime? UpdatedAt { get; set; }
24+
25+
[JsonProperty("created_at")]
26+
public DateTime? CreatedAt { get; set; }
27+
28+
[JsonProperty("last_accessed_at")]
29+
public DateTime? LastAccessedAt { get; set; }
30+
31+
[JsonProperty("size")]
32+
public int? Size { get; set; }
33+
34+
[JsonProperty("cache_control")]
35+
public string? CacheControl { get; set; }
36+
37+
[JsonProperty("content_type")]
38+
public string? ContentType { get; set; }
39+
40+
[JsonProperty("etag")]
41+
public string? Etag { get; set; }
42+
43+
[JsonProperty("last_modified")]
44+
public DateTime? LastModified { get; set; }
45+
46+
[JsonProperty("metadata")]
47+
public Dictionary<string, string>? Metadata { get; set; }
48+
}
49+
}

Storage/Interfaces/IStorageFileApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public interface IStorageFileApi<TFileObject>
1818
Task<string> DownloadPublicFile(string supabasePath, string localPath, TransformOptions? transformOptions = null, EventHandler<float>? onProgress = null);
1919
string GetPublicUrl(string path, TransformOptions? transformOptions = null);
2020
Task<List<TFileObject>?> List(string path = "", SearchOptions? options = null);
21+
Task<FileObjectV2?> Find(string path);
2122
Task<bool> Move(string fromPath, string toPath, DestinationOptions? options = null);
2223
Task<bool> Copy(string fromPath, string toPath, DestinationOptions? options = null);
2324
Task<TFileObject?> Remove(string path);

Storage/StorageFileApi.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ await Helpers.MakeRequest<List<FileObject>>(HttpMethod.Post, $"{Url}/object/list
132132

133133
return response;
134134
}
135+
136+
/// <summary>
137+
/// Retrieves the details of an existing file.
138+
/// </summary>
139+
/// <param name="path"></param>
140+
/// <returns></returns>
141+
public async Task<FileObjectV2?> Find(string path)
142+
{
143+
var response =
144+
await Helpers.MakeRequest<FileObjectV2>(HttpMethod.Get, $"{Url}/object/info/{BucketId}/{path}", null, Headers);
145+
146+
return response;
147+
}
135148

136149
/// <summary>
137150
/// Uploads a file to an existing bucket.
@@ -464,6 +477,14 @@ private async Task<string> UploadOrUpdate(string localPath, string supabasePath,
464477
if (options.Upsert)
465478
headers.Add("x-upsert", options.Upsert.ToString().ToLower());
466479

480+
if (options.Metadata != null)
481+
headers.Add("x-metadata", ParseMetadata(options.Metadata));
482+
483+
options.Headers?.ToList().ForEach(x => headers.Add(x.Key, x.Value));
484+
485+
// if (options.Duplex != null)
486+
// headers.Add("x-duplex", options.Duplex.ToLower());
487+
467488
var progress = new Progress<float>();
468489

469490
if (onProgress != null)
@@ -474,6 +495,14 @@ private async Task<string> UploadOrUpdate(string localPath, string supabasePath,
474495
return GetFinalPath(supabasePath);
475496
}
476497

498+
private static string ParseMetadata(Dictionary<string, string> metadata)
499+
{
500+
var json = JsonConvert.SerializeObject(metadata);
501+
var base64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(json));
502+
503+
return base64;
504+
}
505+
477506
private async Task<string> UploadOrUpdate(byte[] data, string supabasePath, FileOptions options,
478507
EventHandler<float>? onProgress = null)
479508
{
@@ -488,6 +517,14 @@ private async Task<string> UploadOrUpdate(byte[] data, string supabasePath, File
488517
if (options.Upsert)
489518
headers.Add("x-upsert", options.Upsert.ToString().ToLower());
490519

520+
if (options.Metadata != null)
521+
headers.Add("x-metadata", ParseMetadata(options.Metadata));
522+
523+
options.Headers?.ToList().ForEach(x => headers.Add(x.Key, x.Value));
524+
525+
if (options.Duplex != null)
526+
headers.Add("x-duplex", options.Duplex.ToLower());
527+
491528
var progress = new Progress<float>();
492529

493530
if (onProgress != null)

0 commit comments

Comments
 (0)