Exemplo n.º 1
0
 public async Task CreateDirectoryAsync(CreateDirectoryModel input)
 {
     var dto = new CreateFileInput
     {
         FileContainerName = input.FileContainerName,
         OwnerUserId       = input.OwnerUserId,
         FileName          = input.DirectoryName,
         FileType          = FileType.Directory,
         MimeType          = null,
         ParentId          = input.ParentId,
         Content           = null
     };
     await _service.CreateAsync(dto);
 }
Exemplo n.º 2
0
        public async Task CreateAsync()
        {
            var result = await _fileAppService.CreateAsync(new FileUploadInputDto()
            {
                Name  = "微信图片_20200813165555.jpg",
                Bytes = await File.ReadAllBytesAsync(@"D:\WorkSpace\WorkFiles\杂项\图片\微信图片_20200813165555.jpg")
            });

            result.ShouldNotBeEmpty();
        }
Exemplo n.º 3
0
        public async Task <FileUploadResultDto> CreateAsync(IFormFile file)
        {
            await using var ms = new MemoryStream();
            await file.CopyToAsync(ms);

            var result = await _fileAppService.CreateAsync(new FileUploadInputDto
            {
                Name  = file.FileName,
                Bytes = ms.ToArray()
            });

            return(result);
        }
Exemplo n.º 4
0
        public async Task Create_FindByBlobName_Test()
        {
            var blobName = await _fileAppService.CreateAsync(new FileDto()
            {
                FileName = "微信图片_20200813165555.jpg",
                Bytes    = await System.IO.File.ReadAllBytesAsync(@"D:\WorkSpace\WorkFiles\杂项\图片\微信图片_20200813165555.jpg")
            });

            blobName.ShouldNotBeEmpty();

            var fileDto = await _fileAppService.FindByBlobNameAsync(blobName);

            fileDto.ShouldNotBeNull();
            fileDto.FileName.ShouldBe("微信图片_20200813165555.jpg");
        }
        public virtual async Task <IActionResult> OnPostAsync()
        {
            var dto = new CreateFileInput
            {
                FileContainerName = FileContainerName,
                OwnerUserId       = OwnerUserId,
                FileName          = DirectoryName,
                FileType          = FileType.Directory,
                MimeType          = null,
                ParentId          = ParentId,
                Content           = null
            };

            await _service.CreateAsync(dto);

            return(NoContent());
        }
Exemplo n.º 6
0
        public async Task <CreateFileOutput> CreateAsync([FromForm] CreateFileActionInput input)
        {
            if (input.File == null)
            {
                throw new NoUploadedFileException();
            }

            var fileName = input.GenerateUniqueFileName ? GenerateUniqueFileName(input.File) : input.File.FileName;

            await using var memoryStream = new MemoryStream();

            await input.File.CopyToAsync(memoryStream);

            return(await _service.CreateAsync(new CreateFileInput
            {
                FileContainerName = input.FileContainerName,
                FileName = fileName,
                MimeType = input.File.ContentType,
                FileType = input.FileType,
                ParentId = input.ParentId,
                OwnerUserId = input.OwnerUserId,
                Content = memoryStream.ToArray()
            }));
        }
Exemplo n.º 7
0
        public async Task <ImportResultDto> ImportExcel(ImportExcelInput input)
        {
            IExcelImporter Importer = new ExcelImporter();
            var            stream   = new MemoryStream(input.Bytes);
            var            import   = await Importer.Import <ArticleImportDto>(stream);

            var result = new ImportResultDto
            {
                HasError       = import.HasError,
                RowErrors      = import.RowErrors,
                TemplateErrors = import.TemplateErrors,
            };

            if (import.RowErrors != null && import.RowErrors.Count > 0)
            {
                var newStream = new MemoryStream(stream.ToArray());
                Importer.OutputBussinessErrorData <ArticleImportDto>(newStream, import.RowErrors.ToList(), out byte[] fileByte);
                var createFileOutput = await _fileService.CreateAsync(new CreateFileInput
                {
                    FileContainerName = FileContainerNameConsts.Temp,
                    FileName          = input.FileName,
                    MimeType          = input.MimeType,
                    FileType          = FileType.RegularFile,
                    ParentId          = null,
                    OwnerUserId       = CurrentUser.Id,
                    Content           = fileByte
                });

                result.ErrorFile = createFileOutput;
                return(result);
            }
            var entitys = ObjectMapper.Map <List <ArticleImportDto>, List <Article> >(import.Data.ToList());
            await _repository.InsertManyAsync(entitys);

            return(result);
        }
Exemplo n.º 8
0
 public Task <FileUploadOutputDto> CreateAsync(FileUploadInputDto input)
 {
     return(_fileAppService.CreateAsync(input));
 }