Example #1
0
        public async Task <IActionResult> UploadImage(IFormFile image)
        {
            if (image == null || image.Length == 0)
            {
                return(BadRequest());
            }

            var filePath = Path.GetTempFileName();

            using (var stream = new FileStream(filePath, FileMode.Create))
                await image.CopyToAsync(stream);

            UploadImageInput input = new UploadImageInput()
            {
                OriginalFileName = image.FileName,
                ContentType      = image.ContentType,
                LocalPath        = filePath
            };

            Result <UploadImageOutput> result =
                await _fileUploader.UploadImageAsync(input);

            if (result.Success)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }