Example #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)));
        }
Example #2
0
        public async Task <string> SaveFormFileAndGetUrlAsync(IFormFile file)
        {
            var uniqueFileName = await SaveFileInternalAsync(file.FileName, file.AsBytes());

            return(GetFileUrl(uniqueFileName));
        }