Beispiel #1
0
        // POST api/<controller>
        public async Task <ActionResult> SaveChunk()
        {
            //var httpRequest = HttpContext.Current.Request;
            var httpRequest         = Request;
            var azureFileChunkModel = new AzureFileChunkModel()
            {
                ContainerName = httpRequest.Form["tempContainerPath"] ?? Guid.NewGuid().ToString(),
                BlobName      = httpRequest.Form["name"],
                BlockId       = httpRequest.Form["chunkId"],
            };

            var isLastChunk       = Convert.ToBoolean(httpRequest.Form["isLastChunk"]);
            var file              = httpRequest.Files["fileChunk"];
            var chunkIdList       = httpRequest.Form["chunkIdList"];
            var contentType       = httpRequest.Form["contentType"];
            var autoCommitEnabled = Convert.ToBoolean(httpRequest.Form["autoCommitEnabled"]);

            if (file == null || String.IsNullOrWhiteSpace(azureFileChunkModel.BlobName) ||
                String.IsNullOrWhiteSpace(azureFileChunkModel.BlockId))
            {
                throw new ArgumentNullException("Name, ChunkId and File content all are required");
            }

            azureFileChunkModel.Blocks = new byte[file.ContentLength];
            file.InputStream.Read(azureFileChunkModel.Blocks, 0, Convert.ToInt32(file.ContentLength));

            await _azureFileStorageApplicationService.SaveFileChunkAsync(azureFileChunkModel);

            if (isLastChunk && autoCommitEnabled)
            {
                return(await SaveBlob(azureFileChunkModel.ContainerName, azureFileChunkModel.BlobName, chunkIdList, contentType));
            }

            return(Json(new { tempContainerPath = azureFileChunkModel.ContainerName }));
        }
        public async Task SaveFileChunkAsync(AzureFileChunkModel azureFileChunkModel)
        {
            //TODO: Validations
            try
            {
                var container = _cloudClient.GetContainerReference(azureFileChunkModel.ContainerName);
                await container.CreateIfNotExistsAsync();

                var blockBlock = container.GetBlockBlobReference(azureFileChunkModel.BlobName);
                using (var chunkStream = new MemoryStream(azureFileChunkModel.Blocks))
                {
                    try
                    {
                        blockBlock.PutBlock(azureFileChunkModel.BlockId, chunkStream, null);
                    }
                    catch (StorageException e)
                    {
                        throw new StorageException("File upload failed");
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
0
 public async Task SaveFileChunkAsync(AzureFileChunkModel azureFileChunkModel)
 {
     await _azureFileStorageRepositoryService.SaveFileChunkAsync(azureFileChunkModel);
 }
Beispiel #4
0
 public async Task SaveFileChunkAsync(AzureFileChunkModel azureFileChunkModel)
 {
     await _azureFileStorageBusinessService.SaveFileChunkAsync(azureFileChunkModel);
 }