【发布时间】:2021-04-15 04:10:41
【问题描述】:
我想在我的种子函数中创建一个 FormFile。但我得到一个空引用异常。这是我的代码
FileStream fs = new FileStream("testfile.jpg", FileMode.Open, FileAccess.Read);
FormFile file = new FormFile(fs, 1024, fs.Length, "testfile", "testfile.jpg");
file.ContentType = "image/jpeg";
当我尝试设置内容类型时会出现空引用。任何想法我做错了什么?之前使用返回 true 的 File.Exists 检查。
【问题讨论】:
-
您是否尝试过在新的 FileStream 中使用完整路径而不是仅使用文件名?