Ejemplo n.º 1
0
        public async Task <IActionResult> FileUpload([FromForm] PictureDto picture)
        {
            if (picture.File.Length == 0 || picture.File == null)
            {
                return(BadRequest());
            }
            var thumb  = _hostingEnvironment.SubFilderPath(@"Thums\");
            var upload = _hostingEnvironment.UploadPath();

            if (!_hostingEnvironment.DirectoryExist(upload) || !_hostingEnvironment.DirectoryExist(thumb))
            {
                return(BadRequest());
            }
            var url = await _fileService.CreateThumbnail(picture.File, 250, 250, thumb, picture.Title);

            await _fileService.SaveImage(picture.File, 450, 450, upload, picture.Title);

            return(Ok(url.Remove(0, _hostingEnvironment.WebRootPath.Length).Replace(@"\", "/").Insert(0, "~")));
        }