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 ...
随机推荐
- browserslist详解
https://www.jianshu.com/p/d45a31c50711 https://juejin.im/post/5b8cff326fb9a019fd1474d6 https://githu ...
- 表格插件BootStrap-Table使用教程
Bootstrap table 是一款基于 Bootstrap 的 jQuery 表格插件,功能比较完备,能够实现数据异步获取,编辑,排序等一系列功能. 官网https://bootstrap-tab ...
- dfs與bfs常用模板
基本遍歷: //dfs void dfs(int x) { v[x]=1; for(int i=head[x];i;i=next[i]) { int y=ver[i]; if(v[y]) contin ...
- csv文件快速转存到mysql
目录 csv文件快速转存到mysql 连接数据库 读取csv文件内容: 创表: csv数据导入样式: 完整脚本: csv文件快速转存到mysql 连接数据库 连接数据库: con = pymysql. ...
- vue中使用element-ui自定义主题后,vue-cli跑不起来了
环境:vue-cli 2.x版本 自己在官网配置了主题并放到了项目中https://element.eleme.cn/#/zh-CN/theme 然后,我的脚手架在我的电脑中休息了几天,就跑不通了呢! ...
- Centos目录及其常用处理命令
1.Centos之常见目录作用介绍[1] 我们先切换到系统根目录 / 看看根目录下有哪些目录 [root@localhost ~]# cd / [root@localhost /]# ls bin ...
- DDR3(5):读写仲裁
上一讲我们完成了读的控制,但是并不知道是否设计成功,必须读写结合才行.DDR3 的 app 端的命令总线是读写复用的,因此可能会存在读写冲突的时刻,为了解决此问题,必须进行分时读写,也就是我们说的仲裁 ...
- NodeJS 使用内容以及模拟一个接口
1.结合上一篇 安装完Nodejs之后 通过手动创建一个完整的NodeJs项目 2.https://www.jianshu.com/p/7b0a5d4491ba 创建一个完整的项目之后 3.下面是一个 ...
- 更新Linux内核
说明:为了安装Docker,当前虚拟机不满足要求,版本如下: [root@localhost116 ~]# uname -r -.el6.x86_64 [root@localhost116 ~]# c ...
- Codeforces Round #588 (Div. 1)
Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数 ...