public async Task <ActionResult <FileEntry> > Upload([FromForm] UploadFile model)
        {
            var fileEntry = new FileEntry
            {
                Name         = model.Name,
                Description  = model.Description,
                Size         = model.FormFile.Length,
                UploadedTime = DateTime.Now,
                FileName     = model.FormFile.FileName,
            };

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            var fileEntryDTO = fileEntry.ToFileEntryDTO();

            using (var stream = new MemoryStream())
            {
                await model.FormFile.CopyToAsync(stream);

                _fileManager.Create(fileEntryDTO, stream);
            }

            fileEntry.FileLocation = fileEntryDTO.FileLocation;

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            return(Ok(fileEntry));
        }
        public async Task <IActionResult> Upload(UploadFile model)
        {
            var fileEntry = new FileEntry
            {
                Name         = model.Name,
                Description  = model.Description,
                Size         = model.FormFile.Length,
                UploadedTime = DateTime.Now,
                FileName     = model.FormFile.FileName,
            };

            _fileEntryService.Add(fileEntry);

            using (var stream = new MemoryStream())
            {
                await model.FormFile.CopyToAsync(stream);

                _fileManager.Create(fileEntry, stream);
            }

            _fileEntryService.Update(fileEntry);

            _fileUploadedEventSender.Send(new FileUploadedEvent
            {
                FileEntry = fileEntry,
            });

            return(View());
        }
Beispiel #3
0
        public async Task <ActionResult <FileEntry> > Upload([FromForm] UploadFile model)
        {
            var fileEntry = new FileEntry
            {
                Name         = model.Name,
                Description  = model.Description,
                Size         = model.FormFile.Length,
                UploadedTime = DateTime.Now,
                FileName     = model.FormFile.FileName,
                Encrypted    = model.Encrypted,
            };

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            var fileEntryDTO = fileEntry.ToFileEntryDTO();

            if (model.Encrypted)
            {
                var key = SymmetricCrypto.GenerateKey(16);
                using (var inputStream = model.FormFile.OpenReadStream())
                    using (var encryptedStream = new MemoryStream(inputStream
                                                                  .UseAES(key)
                                                                  .WithCipher(CipherMode.ECB)
                                                                  .WithPadding(PaddingMode.PKCS7)
                                                                  .Encrypt()))
                    {
                        _fileManager.Create(fileEntryDTO, encryptedStream);
                    }

                fileEntry.EncryptionKey = key.ToBase64String();
            }
            else
            {
                using (var stream = model.FormFile.OpenReadStream())
                {
                    _fileManager.Create(fileEntryDTO, stream);
                }
            }

            fileEntry.FileLocation = fileEntryDTO.FileLocation;

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            return(Ok(fileEntry));
        }
Beispiel #4
0
        public async Task <IActionResult> Upload(UploadFile model)
        {
            var fileEntry = new FileEntry
            {
                Name         = model.Name,
                Description  = model.Description,
                Size         = model.FormFile.Length,
                UploadedTime = DateTime.Now,
                FileName     = model.FormFile.FileName,
            };

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            using (var stream = new MemoryStream())
            {
                await model.FormFile.CopyToAsync(stream);

                _fileManager.Create(fileEntry, stream);
            }

            _dispatcher.Dispatch(new AddOrUpdateEntityCommand <FileEntry>(fileEntry));

            return(View());
        }