InvalidOperationException: No file provider has been configured to process the supplied file.
现在有一个api, 提供图片的下载,如下代码,,调试出现
InvalidOperationException: No file provider has been configured to process the supplied file. 的错误。
var rootPath = _hostingEnvironment.ContentRootPath;
var photoName= "photo.jpeg";
bitmap.Save($@"{rootPath}\{photoName}", ImageFormat.Jpeg); // 变量bitmap 为Bitmap实例
return File(rootPath, "image/jpeg", photoName);
经过查找可以这样写,如下代码,这样就返回解决了问题。
var rootPath = _hostingEnvironment.ContentRootPath;
var photoName= "photo.jpeg";
bitmap.Save($@"{rootPath}\{photoName}", ImageFormat.Jpeg);
// 一种方式
var provider = new PhysicalFileProvider(rootPath); // 或者这样写 var provider = _hostingEnvironment.ContentRootFileProvider;
var fileInfo = provider.GetFileInfo(photoName);
var readStream = fileInfo.CreateReadStream();
// 另一种更直接的方式// var readStream = System.IO.File.ReadAllBytes($@"{rootPath}\{photoName}");
return File(readStream, "image/jpeg", photoName);
参考:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/file-providers?view=aspnetcore-2.2
本随笔链接:https://www.cnblogs.com/OneManStep/p/11358658.html
InvalidOperationException: No file provider has been configured to process the supplied file.的更多相关文章
- No database provider has been configured for this DbContext
var context = ((IInfrastructure<IServiceProvider>)set).GetService<DbContext>(); 在EF Core ...
- 如何在ASP.NET Core中自定义Azure Storage File Provider
文章标题:如何在ASP.NET Core中自定义Azure Storage File Provider 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p ...
- ORA-00245: control file backup failed; target is likely on a local file system (转载)
环境:DB VERSION: 11.2.0.4.0RAC 2 nodes 问题:邮件显示rman备份失败,查看rman备份日志 Starting Control File and SPFILE Aut ...
- ORA-00245: control file backup failed; target is likely on a local file system
ORACLE11G RAC alert报错如下:Errors in file /u01/app/oracle/diag/rdbms/dljyzs/dljyzs1/trace/dljyzs1_ora_8 ...
- [iOS] file patterns: The `public_header_files` pattern did not match any file.
由于之前集成私有pod,遇到问题, 默认的头文件目录设置为:s.public_header_files = ‘Pod/Classes/**/*.h’:但是如果Classes目录中,你的代码文件夹层次结 ...
- RLException: XXX is neither a launch file in package XXX nor is XXX a launch file name问题解决
在运行roslaunch时出现了类似下面的错误: RLException: XXX is neither a launch file in package XXX nor is XXX a launc ...
- qemu 出现Could not access KVM kernel module: No such file or directory failed to initialize KVM: No such file or directory
使用qemu命令 qemu-system-x86_64 -hda image/ubuntu-test.img -cdrom ubuntu-16.04.2-server-amd64.iso -m 102 ...
- File常用的方法操作、在磁盘上创建File、获取指定目录下的所有文件、File文件的重命名、将数据写入File文件
文章目录 1.基本介绍 2.构造方法 3.常用的方法 4.代码实例 4.1 创建文件和目录(目录不存在) 4.1.1 代码 4.1.2 测试结果 4.2 测试目录存在的情况.直接写绝对的路径名 4.2 ...
- vim - save current file with a new name but keep editing current file
http://superuser.com/questions/414110/vim-save-a-file-as-a-different-filename-but-keep-w-as-the-curr ...
随机推荐
- Arduino读取ph试剂浓度
https://detail.tmall.com/item.htm?id=600904840315&spm=a1z09.2.0.0.31cd2e8d1sb06V&_u=e1qf7bf5 ...
- Lotus words
We are going to memorize a lot of words in the fourth grade of primary school. It's very difficult f ...
- docker nginx 命令。
docker run -d -p 80:80 -p 443:443 --name baiqian.site --restart=always -v ~/wwwroot/layx:/usr/share/ ...
- DB2数据库
必需步骤: 您已经启用了 DB2 扩展 Windows 安全性.您必须将运行 DB2 本地应用程序或工具的 DB2 用户添加至 DB2ADMNS 或DB2USER 组 可以使用端口号 "50 ...
- jieba分词wordcloud词云
1.jieba库的基本介绍 (1).jieba是优秀的中文分词第三方库 中文文本需要通过分词获得单个的词语 jieba是优秀的中文分词第三方库,需要额外安装 jieba库提供三种分词模式,最简单只需掌 ...
- 以py脚本形式ORM操作 及 django终端打印sql语句的设置
1. 在Django项目的settings.py文件中,在最后复制粘贴如下代码: LOGGING = { 'version': 1, 'disable_existing_loggers': False ...
- Mac下Sublime Text常用插件
Mac下Sublime Text常用插件 SideBarEnhancements 右键菜单增强插件 BracketHighlighter 括号.引号.标签高亮插件 Pretty JSON JSON美化 ...
- CentOS 7搭建本地yum源和局域网yum源
这两天在部署公司的测试环境,在安装各种中间件的时候,发现各种依赖都没有:后来一检查,发现安装的操作系统是CentOS Mini版,好吧,我认了:为了完成测试环境的搭建,我就搭建了一个局域网的yum源. ...
- linux shell提示输入 输错字符解决方法
linux shell提示输入 输错字符解决方法ctrl+回车 删除单个字符ctrl+u删除光标前全部字符ctrl+k删除光标后全部字符
- scala基础题--面向对象2
练习2:根据下图实现类.在TestCylinder类中创建Cylinder类的对象,设置圆柱的底面半径和高,并输出圆柱的体积 import scala.beans.BeanProperty objec ...