예제 #1
0
        public IActionResult UploadImage(IFormFile file)
        {
            if (file == null)
            {
                return(BadRequest(new ErrorResponse("Bad request format.")));
            }

            // The HttpImageStream will scrutinise the Content-Type header
            // to make sure the file is a valid image format and return
            // null if not
            IImageStream image = HttpImageStream.CreateFromIFormFile(file);

            if (image == null)
            {
                return(BadRequest(new ErrorResponse("Invalid image or unsupported format.")));
            }

            int id;

            try
            {
                id = _imageProvider.CreateImage(image);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new ErrorResponse(ex.Message)));
            }

            return(Ok(id));
        }