Esempio n. 1
0
        public async Task <IActionResult> Upload(
            string dirPath,
            [FromForm] UploadRequest request,
            [FromServices] IMediator mediator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ViewData["DirPath"] = dirPath;
            var directryPath = new FilePath(dirPath ?? "");

            foreach (var file in request.Files)
            {
                using (var stream = file.OpenReadStream())
                {
                    var data = await _storage.CreateAsync(_storage.CreateKey(), stream).ConfigureAwait(false);

                    var filePath = directryPath.Combine(System.IO.Path.GetFileName(file.FileName ?? "NONAME"));
                    var command  = new CreateOrUpdateDocumentCommand
                    {
                        Path        = filePath,
                        Data        = data,
                        ForceCreate = true
                    };
                    var response = await mediator.Send(command).ConfigureAwait(false);
                }
            }
            return(Redirect(Url.ViewFile(directryPath.ToString())));
        }
Esempio n. 2
0
        private async Task <IActionResult> PostInternal(
            UploadRequest request,
            IMediator mediator)
        {
            if (!FilePath.TryParse(request.Path, out var filepath))
            {
                return(BadRequest("invalid path name."));
            }

            var command = new CreateOrUpdateDocumentCommand
            {
                Path         = filepath,
                Data         = request.File,
                Created      = request.Created?.ToUniversalTime(),
                LastModified = request.LastModified?.ToUniversalTime()
            };
            await mediator.Send(command).ConfigureAwait(false);

            return(CreatedAtAction("Get", new { path = HttpUtility.UrlEncode(command.Path.ToString()) }));
        }