ASP.NET MVC FileStreamResult not working as intended

笑着哭i 提交于 2019-11-29 01:05:50

You need to insert

stream.Seek(0, SeekOrigin.Begin);

after the call to

Image.Save()

This will rewind the stream to the beginning of the saved image. Otherwise the stream will be positioned at the end of the stream and nothing is sent to the receiver.

Try rewinding the MemoryStream. The "cursor" is left at the end of the file and there is nothing to read until you "rewind" the stream to the beginning.

 image.Save( stream, ImageFormat.Jpeg );
 stream.Seek( 0, SeekOrigin.Begin );
 return new FileStreamResult( stream, "image/jpeg" );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!