public async Task <IActionResult> CreateSAS(SASToken token) { if (token == null) { return(BadRequest()); } switch (token.TokenSubject) { case SASTokenSubjects.Blob: var blob = await _blobStore.GetByIdAsync(token.BlobId); if (blob == null) { return(NotFound($"SAS subject blob {token.BlobId} not found.")); } break; case SASTokenSubjects.Container: var container = await _containerStore.GetAsync(token.ContainerId); if (container == null) { return(NotFound($"SAS subject container {token.ContainerId} not found.")); } break; } token = await _sasStore.AddAsync(token); return(Ok(token)); }
// 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)); }
public async Task <IActionResult> UpdateContainerAsync(string id, [FromBody] ContainerCreateModel model) { if (model == null) { return(BadRequest()); } var container = await _containerStore.GetAsync(id); if (container == null) { return(NotFound()); } container.Name = model.Name; var updatedContainer = await _containerStore.UpdateAsync(id, container); var updatedContainerModel = ModelMapper.ToViewModel(updatedContainer); return(Ok(updatedContainerModel)); }