Interface IObjectStorage
- Namespace
- Builvero.Application.Interfaces.Services
- Assembly
- Builvero.Application.dll
Abstraction for object storage operations (S3, local storage, etc.). Allows feature-flagging and test-safe implementations.
public interface IObjectStorage
Methods
DeleteAsync(string, CancellationToken)
Deletes a file from storage
Task<bool> DeleteAsync(string objectKey, CancellationToken cancellationToken = default)
Parameters
objectKeystringStorage object key
cancellationTokenCancellationTokenCancellation token
Returns
GenerateGetUrlAsync(string, TimeSpan?, CancellationToken)
Generates a pre-signed GET URL for retrieving a file from storage. This method may return a plain public URL if UsePublicUrls=true (for backward compatibility). For guaranteed presigned URLs, use GeneratePresignedGetUrlAsync instead.
Task<string> GenerateGetUrlAsync(string objectKey, TimeSpan? expiresIn = null, CancellationToken cancellationToken = default)
Parameters
objectKeystringStorage object key
expiresInTimeSpan?Time until the URL expires
cancellationTokenCancellationTokenCancellation token
Returns
GeneratePresignedGetUrlAsync(string, TimeSpan?, CancellationToken)
Generates a pre-signed GET URL for retrieving a file from storage. This method ALWAYS returns a presigned URL, regardless of UsePublicUrls setting. Use this method when you need a guaranteed presigned URL (e.g., for private buckets).
Task<string> GeneratePresignedGetUrlAsync(string objectKey, TimeSpan? expiresIn = null, CancellationToken cancellationToken = default)
Parameters
objectKeystringStorage object key
expiresInTimeSpan?Time until the URL expires
cancellationTokenCancellationTokenCancellation token
Returns
GenerateUploadUrlAsync(string, string, TimeSpan?, CancellationToken)
Generates a pre-signed URL for uploading a file to storage
Task<(string UploadUrl, string ObjectKey)> GenerateUploadUrlAsync(string objectKey, string contentType, TimeSpan? expiresIn = null, CancellationToken cancellationToken = default)
Parameters
objectKeystringStorage object key (e.g., "profile-photos/{userId}/{uuid}.jpg")
contentTypestringMIME type of the file
expiresInTimeSpan?Time until the URL expires
cancellationTokenCancellationTokenCancellation token
Returns
UploadAsync(string, Stream, string, CancellationToken)
Uploads a file directly to storage (server-side upload)
Task<string> UploadAsync(string objectKey, Stream fileStream, string contentType, CancellationToken cancellationToken = default)
Parameters
objectKeystringStorage object key
fileStreamStreamThe file stream to upload
contentTypestringMIME type of the file
cancellationTokenCancellationTokenCancellation token