简体   繁体   English

从当前HTML页面上传图像

[英]Upload image from current HTML page

I have an image on my HMTL page. 我的HMTL页面上有一张图片。 This is generated by DevExpress library at runtime and the src url points to a DevExpress script with a cache key: 这是由DevExpress库在运行时生成的,并且src url指向带有缓存键的DevExpress脚本:

<img id="Chart_89_IMG" src="/DXB.axd?DXCache=30f02093-de66-4ed6-8557-2382065c701a" />

I'm trying to get this file onto the server in a subsequent form post to use in an email. 我正在尝试将该文件以后续形式发布到服务器上,以用于电子邮件中。 I've tried just passing the url in my form, but by the time it gets to the server, I get a 404 (assuming the cache key is expired). 我已经尝试过仅以表单形式传递url,但是当它到达服务器时,我得到了404(假设高速缓存密钥已过期)。

I've also tried using canvas to get the bytes and pass that to the server, but was having trouble converting that byte stream back to an image, and canvas won't work for IE8, which I need to support. 我也尝试过使用canvas获取字节并将其传递给服务器,但是在将该字节流转换回图像时遇到了麻烦,并且canvas无法用于我需要支持的IE8。

My last idea was to include a file upload input on my form and pass the image to the server that way. 我的最后一个想法是在表单上包含文件上传输入,然后以这种方式将图像传递到服务器。 But, how can I create a file from an image in javascript to use as an upload? 但是,如何从javascript中的图像创建文件以用作上传?

Any other ideas would be appreciated too! 任何其他想法也将不胜感激!

Since this was DevExpress, I was able to change the BinaryStorageMode to the session: 由于这是DevExpress,因此我可以将BinaryStorageMode更改为会话:

settings.BinaryStorageMode = BinaryStorageMode.Session;

Then after I posted the form, the chart's bytes were accessible in the Session: 然后,在我发布表单之后,可以在Session中访问图表的字节:

byte[] bytes = ((DevExpress.Web.ASPxClasses.BinaryStorageData)HttpContext.Current.Session[sessionKey]).Content;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM