使用 OpenRasta 以流或字节数组形式获取图像
任何人都可以给我一个关于如何获得返回字节数组的 OpenRasta 处理程序的快速指示。在 ResourceSpace 中公开,而不是 JSON 或 XML 对象。即我不想对其进行转码,我只是希望能够将媒体类型设置为“image/PNG”或类似类型。
使用 ASP.Net MVC,我可以使用 FileContentResult 通过返回来完成此操作,
File(myByteArray, "image/PNG");
我只需要知道 OpenRasta 等效项。
谢谢
Would anyone be able to give me a quick pointer as to how I can get an OpenRasta handler that returns a byte array. To be exposed in the ResourceSpace without it being a JSON or XML object. i.e. I don't want it transcoded, I just want to be able to set the media type to "image/PNG" or similar.
Using ASP.Net MVC I can do it using a FileContentResult by returning
File(myByteArray, "image/PNG");
I just need to know the OpenRasta equivalent.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以只返回一个字节数组作为处理程序的一部分,但这最终将被用作应用程序/八位字节流。
如果你想返回文件,你可以简单地返回 IFile 的实现。
您还可以设置 FileName 属性以返回特定的文件名,这将为您呈现 Content-Disposition 标头。
You can just return a byte array as part of your handlerm but that will end up being served as application/octet-stream.
If you want to return files, you can simply return an implementation of IFile.
You can also set the FileName property to return a specific filename, which will render a Content-Disposition header for you.
我在 OpenRasta 邮件列表上查了一下,有几个相关的帖子:
http://groups.google.com/group/openrasta/browse_thread/thread /5ae2a6d653a7421e#
http://groups.google.com/group/openrasta/browse_thread/thread /a631d3629b25b88a#
我已经使用以下示例进行了操作:
配置:
处理程序:
I looked this up on the OpenRasta mailing list and there were a couple of related posts:
http://groups.google.com/group/openrasta/browse_thread/thread/5ae2a6d653a7421e#
http://groups.google.com/group/openrasta/browse_thread/thread/a631d3629b25b88a#
I have got it going with the following sample:
Configuration:
Handler:
好吧,有一些 Stream 编解码器,但您可以像这样简单地执行此操作,
在我的例子中,图像处理程序返回由 System.Drawing.Graphics 对象组成的字节数组。
任何其他能够进一步阐明该主题的答案将不胜感激。
Well there are some Stream codecs out there, but you can do it as simply as this
where Image handler returns a byte array made from a System.Drawing.Graphics object in my case.
Any other answers that shed more light on this topic would be appreciated.