// TODO add uploading by chunks // TODO refactor public async Task <IActionResult> AddBlobAsync(string containerId, IFormFile file, List <BlobMetaDataCreateModel> MetaData = null) { if (file == null) { return(BadRequest()); } var container = await _containerStore.GetAsync(containerId); if (container == null) { return(NotFound()); } if (FileLengthExceedAllowed(file)) { return(BadRequest()); } var contentType = file.ContentType; var fileName = file.FileName; var buffer = await file.ToByteArrayAsync(); var subject = await _storageService.AddBlobAsync(containerId, buffer); if (string.IsNullOrEmpty(subject)) { return(StatusCode(500)); } string mimeType = MimeMapping.GetMimeMapping(fileName); var blob = await _blobStore.AddAsync(new BlobCreateModel() { ContainerId = containerId, OrigFileName = fileName, MimeType = mimeType, StorageSubject = subject, SizeInBytes = buffer.Length }); var blobModel = ModelMapper.ToViewModel(blob); if (MetaData != null) { foreach (var singleMetaData in MetaData) { await _blobMetaDataStore.AddAsync(blob.Id, singleMetaData); } blobModel.MetaData = ModelMapper.ToViewModelList(await _blobMetaDataStore.GetAllFromBlobAsync(blob.Id)); } return(Ok(blobModel)); }