예제 #1
0
        public async Task <JsonResult> UploadImage(IFormFile file)
        {
            //TODO: localize exception messages

            if (file == null)
            {
                throw new UserFriendlyException("No file found!");
            }

            if (file.Length <= 0)
            {
                throw new UserFriendlyException("File is empty!");
            }

            if (!file.ContentType.Contains("image"))
            {
                throw new UserFriendlyException("Not a valid image!");
            }

            var output = await _fileAppService.UploadAsync(
                new FileUploadInputDto
            {
                Bytes = file.AsBytes(),
                Name  = file.FileName
            }
                );

            return(Json(new FileUploadResult(output.Url)));
        }
예제 #2
0
 public Task <FileUploadOutputDto> UploadAsync(FileUploadInputDto input)
 {
     return(_fileAppService.UploadAsync(input));
 }