Custom Storage Provider
Implement a custom storage provider to save files to any destination: cloud storage, databases, or networked file systems.
What you should see: files stored through a provider you supply rather than the built-in filesystem one. The client side is unchanged — only the server's destination differs. Accepts up to 100 MB.
Drag & drop files here, or paste from clipboard
<core-upload asp-upload-url="/api/upload/upload"
asp-multiple="true"
asp-progress="true"
asp-auto-upload="true"
asp-max-size="100MB">
</core-upload>
<!-- Server-side: implement IStorageProvider -->
public class MyCloudStorageProvider : IStorageProvider
{
public async Task<string> SaveAsync(
Stream stream, string fileName, string contentType)
{
// Upload to your cloud storage
var blobClient = _container
.GetBlobClient(fileName);
await blobClient.UploadAsync(stream);
return blobClient.Uri.ToString();
}
public async Task DeleteAsync(string fileId)
{
var blobClient = _container
.GetBlobClient(fileId);
await blobClient.DeleteIfExistsAsync();
}
public async Task<Stream> GetAsync(string fileId)
{
var blobClient = _container
.GetBlobClient(fileId);
return await blobClient.OpenReadAsync();
}
}
// In Program.cs
builder.Services.AddCoreUpload(options =>
{
options.UseStorageProvider<MyCloudStorageProvider>();
});