<%@ Page Title="Custom Storage Provider" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %> 
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">Custom Storage Provider - AjaxUploader v5.2 Demos</asp:Content>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeaderTitle" runat="server">Custom Storage Provider</asp:Content> 
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> 
<div class="demo-card"> <div class="demo-card-header">Custom Storage Provider</div> <div class="demo-card-body"> <p class="demo-description"> Implement a custom storage provider to save uploaded files to any backend:
 Azure Blob, AWS S3, MongoDB GridFS, or your own storage. Implement the
 <code>IUploaderProvider</code> interface and register it in
 <code>web.config</code> appSettings.
 </p> <au:AjaxFileUpload ID="Uploader1" runat="server"
 AllowMultiple="true"
 AutoUpload="true"
 ShowProgress="true"
 ButtonText="Upload (Custom Provider)" /> <div class="code-panel"> <pre><code>&lt;%-- 1. Implement the IUploaderProvider interface --%&gt;
public class AzureBlobProvider : IUploaderProvider
{
 private readonly CloudBlobContainer _container;

 public AzureBlobProvider()
 {
 string connStr = ConfigurationManager
 .AppSettings["AzureStorageConnection"];
 var account = CloudStorageAccount.Parse(connStr);
 var client = account.CreateCloudBlobClient();
 _container = client.GetContainerReference("uploads");
 _container.CreateIfNotExists();
 }

 public UploadResult Save(
 Stream stream, string fileName, string contentType)
 {
 string blobName = Guid.NewGuid() + "/" + fileName;
 var blob = _container.GetBlockBlobReference(blobName);
 blob.Properties.ContentType = contentType;
 blob.UploadFromStream(stream);
 return new UploadResult
 {
 FileId = blobName,
 FileName = fileName,
 Url = blob.Uri.ToString()
 };
 }

 public FileResult GetFile(string fileId)
 {
 var blob = _container.GetBlockBlobReference(fileId);
 var ms = new MemoryStream();
 blob.DownloadToStream(ms);
 ms.Position = 0;
 return new FileResult
 {
 Stream = ms,
 ContentType = blob.Properties.ContentType
 };
 }

 public void Delete(string fileId)
 {
 _container.GetBlockBlobReference(fileId)
 .DeleteIfExists();
 }
}

&lt;%-- 2. Register in web.config appSettings --%&gt;
&lt;appSettings&gt;
 &lt;add key="AjaxUploader:StorageProvider"
 value="MyApp.Providers.AzureBlobProvider, MyApp" /&gt;
 &lt;add key="AzureStorageConnection"
 value="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=..." /&gt;
&lt;/appSettings&gt;

&lt;%-- 3. Or register in Global.asax Application_Start --%&gt;
protected void Application_Start()
{
 AjaxUploaderConfig.StorageProvider =
 new AzureBlobProvider();
}</code></pre> </div> </div>
</div> 
</asp:Content>
