简体   繁体   English

使用GWT,如何加载图像并访问图像属性和http状态代码

[英]Using GWT, how to load an image and access image attributes & http status codes

Using GWT I am loading images from a server I do not control. 使用GWT,我从不受控制的服务器加载图像。 Currently, I use GWT new Image( url) and then use ImageHandlers and ErrorHandlers to catch what happened and put the images in my buffer and the DOM. 当前,我使用GWT new Image( url) ,然后使用ImageHandlers和ErrorHandlers捕获发生的情况,并将图像放入缓冲区和DOM中。 Then I make the images visible sequently to animate the process. 然后,使图像可见,以动画化该过程。 But now I need a bit more, I need to know the error code, eg304 that the server returned for the image and also I need to get at the header response attribute, 'Last-modified'. 但是现在我还需要更多,我需要知道错误代码,例如服务器为图像返回的错误代码304,并且还需要获取标头响应属性“ Last-modified”。 For 304, I know I need to resubmit the request later when the server will have created a new version ( with exactly the same url ) which I think I can manage, but it will then have a new 'Last-modified' and I need to know that DateTime. 对于304,我知道我需要稍后在服务器将创建我认为可以管理的新版本(具有完全相同的url)时重新提交请求,但随后它将有一个新的“最后修改”,我需要知道那个DateTime。 By using new Image(url), I am letting the browser do the loading, but I don't know how to get at the details of the load. 通过使用新的Image(url),我让浏览器进行加载,但是我不知道如何获得加载的详细信息。

Q1:Is there a way to pull more info from an image? 问题1:是否可以从图片中提取更多信息? GWT Image just seeems to wrap a JS object. GWT Image只是似乎包装了JS对象。 I look in Firefox Console-Network, but don't see much detail there either. 我查看的是Firefox控制台网络,但也没有看到太多细节。 Is Last-modified and error code forgotten by the time it gets (or doesn't) in the DOM tree. 在DOM树中获得(或不获得)时被最后修改并且忘记了错误代码。

If the answer to Q1 is no the information is gone or inaccessible, .. 如果对Q1的回答是否定的,则信息不存在或无法访问,..

Q2: Do I need to stop using the browser to fetch images and do it with an XmlHttpRequest and then presumably I have access to the response codes and the header attributes. Q2:我是否需要停止使用浏览器来获取图像并使用XmlHttpRequest进行处理,然后大概可以访问响应代码和标头属性。 SOP is not an issue. SOP不是问题。 But how then do I get from say the Response OutputStream to an Image? 但是,如何从响应OutputStream转换为图像呢? Do I have to Base64 encode it or is there a better way? 我需要对Base64进行编码还是有更好的方法? Will one of the other non-url constructors for image help, say Image(Element) or Image(ImageResource). 用于图像的其他非URL构造函数之一,例如Image(Element)或Image(ImageResource)。 Then the issue becomes how to make a response stream into a Element or ImageResource? 那么问题就变成了如何使响应流成为Element或ImageResource?

Note: This other question ' How to print error message of why image failed to load? 注意:这另一个问题( 如何打印为什么无法加载图像的错误消息? ' is related, but doesn't get to an answer. '是相关的,但没有答案。

Getting Error codes, and getting the response as a stream must be done with an HTTP client ( GWT has the built in RequestBuilder ). 获取错误代码以及将响应作为流获取必须通过HTTP客户端完成( GWT具有内置的RequestBuilder )。 You can also try to get the error code with native JS, using the method described here . 您也可以使用此处描述的方法,尝试使用本机JS获取错误代码。

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

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