public override async Task <FileDto> CreateAsync(FileDto input) { await DetermineShareUrlAsync(input); var file = await MapToEntityAsync(input); var validationResult = await fileValidator.ValidateAsync(file); if (!validationResult.IsValid) { throw new AbpException(validationResult.Errors[0].ErrorMessage); } return(await base.CreateAsync(input)); }
// TODO Need to figure out how we rollback if cancellation is requested or prevent it? public async Task UploadFileMultipartDocument(Guid userId, string slug, Guid folderId, Stream requestBody, string?contentType, CancellationToken cancellationToken) { var userCanPerformAction = await _permissionsService.UserCanPerformActionAsync(userId, slug, AddFileRole, cancellationToken); if (userCanPerformAction is false) { _logger.LogError($"Error: CreateFileAsync - User:{0} does not have access to group:{1}", userId, slug); throw new SecurityException($"Error: User does not have access"); } var file = await this.UploadMultipartContent(requestBody, contentType, cancellationToken); file.CreatedBy = userId; file.ParentFolder = folderId; var validator = new FileValidator(); var validationResult = await validator.ValidateAsync(file, cancellationToken); if (validationResult.Errors.Count > 0) { throw new ValidationException(validationResult); } try { await CreateFileAsync(file, cancellationToken); } catch (Exception ex) { _logger.LogError(ex, $"Error: CreateFileAsync - Error adding file to database"); await _blobStorageProvider.DeleteFileAsync(file.BlobName); } }