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 ...
随机推荐
- Springboot之自定义配置
SpringBoot自定义配置 springboot在这里就不过多介绍了,大家都应该了解springboot零配置文件,所以配置信息都装配在属性文件(properties.yml.yaml)中,有时我 ...
- 11-散列4 Hashing - Hard Version (30 分)
Given a hash table of size N, we can define a hash function H(x)=x%N. Suppose that the linear probin ...
- 大数据-使用Hive导入10G数据
前言 Hadoop和Hive的环境已经搭建起来了,开始导入数据进行测试.我的数据1G大概对应500W行,MySQL的查询500W行大概3.29秒,用hive同样的查询大概30秒.如果我们把数据增加到1 ...
- 配置Nginx的防盗链
实验环境 一台最小化安装的CentOS 7.3虚拟机 配置:1核心/512MB nginx版本1.12.2 一.配置盗链网站 1.启动一台nginx虚拟机,配置两个网站 vim /etc/nginx/ ...
- bat 文件追加
@echo off set str1=disable_modules:set str2= - mine echo %str1% >> c:\minionecho %str2% >&g ...
- 【Activiti学习之四】Activiti API(三)
环境 JDK 1.8 MySQL 5.6 Tomcat 7 Eclipse-Luna activiti 6.0 一.启动流程 多种方式启动 package com.wjy.pro; import or ...
- jvm jdk jre 关系
JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...
- Appium Grid并发测试
背景 Selenium玩的比较6的同学比较清楚:在Selenium中三大组件中有包含了Selenium Grid,而其作用就是分布式执行测试用例.主要的应用场景在于: 缩短测试执行时间,提高自动化测试 ...
- python入门之数据类型及内置方法
目录 一.题记 二.整形int 2.1 用途 2.2 定义方式 2.3 常用方法 2.3.1 进制之间的转换 2.3.2 数据类型转换 3 类型总结 三.浮点型float 3.1 用途 3.2 定义方 ...
- 大一0基础小白用最基础C写哥德巴赫猜想
#include <stdio.h>int main (){ int a,b,c,k,count1,count2; for(a=4;a<=1200;a=a+2){ for(b=2;b ...