Table of Contents

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

basePath string

Base directory path for file storage (e.g., "/data/storage").

logger ILogger<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

objectKey string

Storage object key

cancellationToken CancellationToken

Cancellation token

Returns

Task<bool>

True if the file was deleted successfully, false if it didn't exist

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

objectKey string

Storage object key

expiresIn TimeSpan?

Time until the URL expires

cancellationToken CancellationToken

Cancellation token

Returns

Task<string>

Pre-signed GET URL or public URL (depending on configuration)

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

objectKey string

Storage object key

expiresIn TimeSpan?

Time until the URL expires

cancellationToken CancellationToken

Cancellation token

Returns

Task<string>

Pre-signed GET URL with X-Amz- query parameters

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

objectKey string

Storage object key (e.g., "profile-photos/{userId}/{uuid}.jpg")

contentType string

MIME type of the file

expiresIn TimeSpan?

Time until the URL expires

cancellationToken CancellationToken

Cancellation token

Returns

Task<(string UploadUrl, string ObjectKey)>

Pre-signed upload URL and the object key

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

objectKey string

Storage object key

fileStream Stream

The file stream to upload

contentType string

MIME type of the file

cancellationToken CancellationToken

Cancellation token

Returns

Task<string>

Object key where the file was stored