public async Task <CreateManyFileOutput> CreateManyAsync([FromForm] CreateManyFileActionInput input)
        {
            if (input.Files.IsNullOrEmpty())
            {
                throw new NoUploadedFileException();
            }

            var createFileDtos = new List <CreateFileInput>();

            foreach (var file in input.Files)
            {
                var fileName = input.GenerateUniqueFileName ? GenerateUniqueFileName(file) : file.FileName;

                await using var memoryStream = new MemoryStream();

                await file.CopyToAsync(memoryStream);

                createFileDtos.Add(new CreateFileInput
                {
                    FileContainerName = input.FileContainerName,
                    FileName          = fileName,
                    MimeType          = file.ContentType,
                    FileType          = input.FileType,
                    ParentId          = input.ParentId,
                    OwnerUserId       = input.OwnerUserId,
                    Content           = memoryStream.ToArray()
                });
            }

            return(await _service.CreateManyAsync(new CreateManyFileInput { FileInfos = createFileDtos }));
        }
Exemple #2
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            var dto = new CreateManyFileInput {
                FileInfos = new List <CreateFileInput>()
            };

            foreach (var uploadedFile in UploadedFiles)
            {
                dto.FileInfos.Add(new CreateFileInput
                {
                    FileContainerName = FileContainerName,
                    OwnerUserId       = OwnerUserId,
                    FileName          = uploadedFile.FileName,
                    FileType          = FileType.RegularFile,
                    MimeType          = uploadedFile.ContentType,
                    ParentId          = ParentId,
                    Content           = await uploadedFile.GetAllBytesAsync()
                });
            }

            await _service.CreateManyAsync(dto);

            return(NoContent());
        }