public async Task <DocumentDTO> CreateAsync(DocumentDTO dto)
        {
            if (dto.File == null)
            {
                throw new EmptyDocumentException();
            }
            string contentType;

            if (dto.File.Length > _options.MaximumSize)
            {
                throw new WrongDocumentSizeException();
            }

            contentType = MimeType.GetMimeType(dto.File.OpenReadStream());
            if (contentType != "application/pdf")
            {
                throw new DocumentContentException();
            }

            dto.ContentType = contentType;
            dto.Path        = _storageLogger.Create(dto.File);


            var model = _mapper.Map <Document>(dto);

            await _unitOfWork.DocumentRepository.AddAsync(model);

            await _unitOfWork.SaveAsync();

            return(_mapper.Map <DocumentDTO>(model));
        }
        public void CanCreateFile(string key, UploadFileInfo uploadFileInfo)
        {
            string testDescription = $"Object can be created by '{key}' key";

            ExecuteCheck(testDescription, async() =>
            {
                await fileStorage.Create(bucket, key, uploadFileInfo.Content, uploadFileInfo.Metadata, uploadFileInfo.MimeType);
            });
        }
        public FileStorage Create(string fileName, string fileCategory)
        {
            var file = new FileStorage
            {
                Name     = fileName,
                Category = fileCategory
            };

            return(_fileRepository.Create(file));
        }
        public async Task <string> Save(IFormFile image, string containerName)
        {
            using var stream = new MemoryStream();
            await image.CopyToAsync(stream);

            var fileBytes = stream.ToArray();

            return(await _fileStorage.Create(new FileHandler
            {
                File = fileBytes,
                ContentType = image.ContentType,
                Extention = Path.GetExtension(image.FileName),
                Container = containerName,
                Name = Guid.NewGuid().ToString()
            }));
        }
示例#5
0
        public async Task <DocumentDTO> CreateAsync(DocumentDTO dto)
        {
            var provider = new FileExtensionContentTypeProvider();

            _ = provider.TryGetContentType(Path.GetFileName(dto.File.FileName), out string contentType);

            dto.ContentType = contentType;
            dto.Path        = _storageLogger.Create(dto.File);


            var model = _mapper.Map <Document>(dto);

            await _unitOfWork.DocumentRepository.AddAsync(model);

            await _unitOfWork.SaveAsync();

            return(_mapper.Map <DocumentDTO>(model));
        }