如何将原始 System.Drawing.Image 传递给 .ashx?
我正在开发一个应用程序,将图像存储为 xml 文件中的 Base64 字符串。我还想允许用户在将图像保存到文件之前裁剪图像,最好全部保存在内存中,而不必保存临时文件,然后将其删除。为了显示新上传的图像,我需要创建一个可以将 asp:Image 绑定到的 HTTP 处理程序。在线执行此操作的唯一示例需要向 .ashx 传递 ID,然后从数据库或其他数据存储中提取映像。是否有可能以某种方式将原始数据传递到 .ashx 以取回图像?
谢谢,
迈克
I am developing an application that stores images as Base64 strings in xml files. I also want to allow the user to crop the image before saving it to the file, preferably all in memory without having to save a temp file, and then delete it afterwards. In order to display the newly uploaded image, I need to create a HTTP handler that I can bind the asp:Image to. The only examples for doing this online require passing the .ashx an ID and then pulling the image from a DB or other data store. Is it possible to somehow pass the raw data to the .ashx in order to get back the image?
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您从未拥有服务器场,您可以将映像置于会话状态。
然而,它并不完全可靠。
做到这一点的最好方法是使用数据库。
Assuming that you never have a server-farm, you could put the image in session state.
However, it would not be completely reliable.
The best way to do this is to use a database.
图像可以像任何其他文件一样POST发送到站点,并且 HttpHandler 可以捕获传入数据并使用它。
诀窍就是获取发布到处理程序的文件的内存表示。
An image can be POST-ed to a site just like any other file, and an HttpHandler can catch the incoming data and work with it.
The trick will just be gettimngthe in-memory representartion of the file posted to the handler.
我最终不得不使用 AJAX 和临时文件来完成这项工作。似乎没有一种简单的方法可以将二进制数据直接传输到处理程序。
I ended up having to just use AJAX and temporary files in order to get this done. There did not appear to be an easy way to transfer binary data directly to the handler.