mvc 提供文件流服务的真正方式是什么?
我有一个错误的方法让 ASP.NET MVC 提供文件流服务。它看起来像这样:
public void SlideThumbnail(Guid id, int? width, int? height)
{
/*make the thumbnail code here*/
using (Bitmap thumbnail = imageThumb.Generate(path))
{
var msOutput = new MemoryStream();
thumbnail.Save(msOutput, ImageFormat.Png);
Response.ContentType = "image/png";
msOutput.WriteTo(Response.OutputStream);
}
}
这非常有效。我尝试修改代码以使用 base.File()
代替。就像这样:
public ActionResult SlideThumbnail(Guid id, int? width, int? height)
{
/*make the thumbnail code here*/
using (Bitmap thumbnail = imageThumb.Generate(path))
{
var msOutput = new MemoryStream();
thumbnail.Save(msOutput, ImageFormat.Png);
return base.File(msOutput, "image/png");
}
}
但这一切似乎实际上并没有起到任何作用。我没有收到任何错误,但也没有收到任何图像:-(
那么我如何以 MVC 方式实现这一点呢?
I have an incorrect way to make asp.net mvc serve a filestream. It looks like this:
public void SlideThumbnail(Guid id, int? width, int? height)
{
/*make the thumbnail code here*/
using (Bitmap thumbnail = imageThumb.Generate(path))
{
var msOutput = new MemoryStream();
thumbnail.Save(msOutput, ImageFormat.Png);
Response.ContentType = "image/png";
msOutput.WriteTo(Response.OutputStream);
}
}
This works super duper. I tried modifying the code to use base.File()
instead. Like this:
public ActionResult SlideThumbnail(Guid id, int? width, int? height)
{
/*make the thumbnail code here*/
using (Bitmap thumbnail = imageThumb.Generate(path))
{
var msOutput = new MemoryStream();
thumbnail.Save(msOutput, ImageFormat.Png);
return base.File(msOutput, "image/png");
}
}
But all this doesn't seem to actually do anything. I don't get any errors, but I also don't get any image :-(
So how do i accomplish this the MVC way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们想通了。我只需要补充一点:
我们都很好。
We figured it out. I just needed to add:
and we're all good.