Class LocalFileStorageService
- Namespace
- Builvero.Infrastructure.Services
- Assembly
- Builvero.Infrastructure.dll
Local file storage implementation that stores files on disk using mounted volumes. Used only when BUILVERO_ENV=local. Mimics S3 semantics with bucket + key abstraction.
public sealed class LocalFileStorageService : IObjectStorage
- Inheritance
-
LocalFileStorageService
- Implements
- Inherited Members
Constructors
LocalFileStorageService(string, ILogger<LocalFileStorageService>)
Initializes a new instance of the LocalFileStorageService class.
public LocalFileStorageService(string basePath, ILogger<LocalFileStorageService> logger)
Parameters
basePathstringBase directory path for file storage (e.g., "/data/storage").
loggerILogger<LocalFileStorageService>Logger for recording file operations.
Methods
DeleteAsync(string, CancellationToken)
Deletes a file from storage
public 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.
public 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).
public 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
public 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)
public 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