Skip to content

Commit

Permalink
Generate signed url for accessing public images
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk committed Mar 9, 2024
1 parent 29d556e commit 54306f2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Inshapardaz.Storage.S3/S3FileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Amazon.S3;
using Amazon.S3.Model;
using Inshapardaz.Domain.Repositories;
using System;
using System.IO;
Expand Down Expand Up @@ -163,7 +164,14 @@ private async Task<byte[]> ReadAllContents(Stream stream)

public string GetPublicUrl(string filePath)
{
return new Uri(new Uri(_configuration.ServiceUrl), $"{_configuration.BucketName}/" + filePath).ToString();
GetPreSignedUrlRequest preSignedUrlRequest = new GetPreSignedUrlRequest
{
BucketName = _configuration.BucketName,
Key = $"{_configuration.FolderName}/{filePath}",
Expires = DateTime.UtcNow.AddMinutes(30)
};

return GetClient().GetPreSignedURL(preSignedUrlRequest);
}
}
}

0 comments on commit 54306f2

Please sign in to comment.