Your search did not match any results.

Direct Upload to Azure

The FileUploader widget supports direct-upload to blob storages. This demo illustrates how to configure the uploadChunk option to upload a large file directly to Azure Blob Storage without using a user's web server.

To implement file upload logic, use the uploadChunk option to specify how to process a connection request to the storage.

@model DevExtreme.NETCore.Demos.Models.FileManagement.AzureStorageAccount @if(!Model.IsEmpty()) { @(Html.DevExtreme().FileUploader() .ID("file-uploader") .ChunkSize(200000) .MaxFileSize(1048576) .UploadChunk("uploadChunk") ) <text> <script src="~/utils/azure-file-system.js"></script> <script> var endpointUrl = '@Url.RouteUrl("FileUploaderAzureAccessApi")'; var gateway = new AzureGateway(endpointUrl); var uploadChunk = function(file, uploadInfo) { var deferred = null; if(uploadInfo.chunkIndex === 0) { deferred = gateway.getUploadAccessUrl(file.name).done(function(accessUrl) { uploadInfo.customData.accessUrl = accessUrl; }); } else { deferred = $.Deferred().resolve().promise(); } deferred = deferred.then(function() { return gateway.putBlock(uploadInfo.customData.accessUrl, uploadInfo.chunkIndex, uploadInfo.chunkBlob); }); if(uploadInfo.chunkIndex === uploadInfo.chunkCount - 1) { deferred = deferred.then(function() { return gateway.putBlockList(uploadInfo.customData.accessUrl, uploadInfo.chunkCount); }); } return deferred; }; </script> </text> } else { <text> To run the demo locally, specify your Azure storage account name, access key and container name in the appsettings.json file. Refer to the <a href="https://demos.devexpress.com/ASPNetCore/Demo/FileUploader/AzureDirectUploading/"> https://demos.devexpress.com/ASPNetCore/Demo/FileUploader/AzureDirectUploading/ </a> to see the demo online. </text> }
using DevExtreme.NETCore.Demos.Models.FileManagement; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public partial class FileUploaderController : Controller { public ActionResult AzureDirectUploading() { return View(AzureStorageAccount.FileUploader); } } }
using DevExtreme.NETCore.Demos.Models.FileManagement; using Microsoft.Azure.Storage; using Microsoft.Azure.Storage.Auth; using Microsoft.Azure.Storage.Blob; using Microsoft.AspNetCore.Mvc; using System; namespace DevExtreme.NETCore.Demos.Controllers.ApiControllers { public class FileUploaderAzureAccessApiController : Controller { const long MaxBlobSize = 1048576; CloudBlobClient _client; CloudBlobClient Client { get { if(this._client == null) { AzureStorageAccount accountModel = AzureStorageAccount.FileUploader; var credentials = new StorageCredentials(accountModel.AccountName, accountModel.AccessKey); var account = new CloudStorageAccount(credentials, true); this._client = account.CreateCloudBlobClient(); } return this._client; } } CloudBlobContainer _container; CloudBlobContainer Container { get { if(this._container == null) { AzureStorageAccount accountModel = AzureStorageAccount.FileUploader; this._container = Client.GetContainerReference(accountModel.ContainerName); } return this._container; } } [Route("api/file-uploader-azure-access", Name = "FileUploaderAzureAccessApi")] public object Process(string command, string blobName) { try { return UploadBlob(blobName); } catch { return CreateErrorResult(); } } object UploadBlob(string blobName) { if(blobName.Contains("/")) return CreateErrorResult("Invalid blob name."); string prefix = Guid.NewGuid().ToString("N"); string fullBlobName = $"{prefix}_{blobName}"; CloudBlockBlob blob = Container.GetBlockBlobReference(fullBlobName); if(blob.Exists() && blob.Properties.Length > MaxBlobSize) { blob.Delete(); return CreateErrorResult(); } var policy = new SharedAccessBlobPolicy { SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1), Permissions = SharedAccessBlobPermissions.Write }; string url = blob.Uri + blob.GetSharedAccessSignature(policy, null, null, SharedAccessProtocol.HttpsOnly, null); return CreateSuccessResult(url); } object CreateSuccessResult(string url, string url2 = null) { return new { success = true, accessUrl = url, accessUrl2 = url2 }; } object CreateErrorResult(string error = null) { if(string.IsNullOrEmpty(error)) error = "Unspecified error."; return new { success = false, error = error }; } } }