Skip to content

Commit

Permalink
Merge pull request #16 from alustrement-bob/fix-createsignedurl-with-…
Browse files Browse the repository at this point in the history
…tranformoptions

Fix CreateSignedUrl with TransformOptions
  • Loading branch information
acupofjose authored May 16, 2024
2 parents 25222bf + 04baf89 commit dc57899
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Storage/StorageFileApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Supabase.Storage.Exceptions;
using Supabase.Storage.Extensions;
using Supabase.Storage.Interfaces;
Expand Down Expand Up @@ -67,7 +68,11 @@ public async Task<string> CreateSignedUrl(string path, int expiresIn, TransformO
var url = $"{Url}/object/sign/{GetFinalPath(path)}";

if (transformOptions != null)
body.Add("transform", transformOptions);
{
var transformOptionsJson = JsonConvert.SerializeObject(transformOptions, new StringEnumConverter());
var transformOptionsObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(transformOptionsJson);
body.Add("transform", transformOptionsObj);
}

var response = await Helpers.MakeRequest<CreateSignedUrlResponse>(HttpMethod.Post, url, body, Headers);

Expand Down
9 changes: 5 additions & 4 deletions Storage/TransformOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Supabase.Core.Attributes;

namespace Supabase.Storage
Expand All @@ -13,11 +14,11 @@ public class TransformOptions
/// </summary>
public enum ResizeType
{
[MapTo("cover")]
[MapTo("cover"), EnumMember(Value = "cover")]
Cover,
[MapTo("contain")]
[MapTo("contain"), EnumMember(Value = "contain")]
Contain,
[MapTo("fill")]
[MapTo("fill"), EnumMember(Value = "fill")]
Fill
}

Expand Down
12 changes: 12 additions & 0 deletions StorageTests/StorageFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ public async Task GetSignedLink()
await _bucket.Remove(new List<string> { name });
}

[TestMethod("File: Get Signed Link with transform options")]
public async Task GetSignedLinkWithTransformOptions()
{
var name = $"{Guid.NewGuid()}.bin";
await _bucket.Upload(new Byte[] { 0x0, 0x1 }, name);

var url = await _bucket.CreateSignedUrl(name, 3600, new TransformOptions { Width = 100, Height = 100 });
Assert.IsTrue(Uri.IsWellFormedUriString(url, UriKind.Absolute));

await _bucket.Remove(new List<string> { name });
}

[TestMethod("File: Get Multiple Signed Links")]
public async Task GetMultipleSignedLinks()
{
Expand Down

0 comments on commit dc57899

Please sign in to comment.