2

I'd like to know whether the image has been modified since some time using GWT. I've found that setting If-Modified-Since http header might work, so I tried to do it like in this post:

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://www.site.com/pic1.jpg");
rb.setHeader("If-Modified-Since", "Sat, 17 Nov 2012 16:17:00 GMT");
Request r = rb.sendRequest(null, new RequestCallback() {
    public void onResponseReceived(Request request, Response response){
         int i = response.getStatusCode();
         ...
    }

    public void onError(Request request, Throwable exception){
        ...
    }

});

The problem is that I get a status code equals to 0. Could you please tell me what am I doing wrong? Is this a good way to know if the file on server has been modified, or, are there any other ways using GWT? Thanks.

Community
  • 1
  • 1
DropDropped
  • 1,253
  • 1
  • 22
  • 50
  • Hm, status code 0 sounds like the same host restriction? Is the image on the same server as the GWT code is started from? – Stefan Haustein Nov 17 '12 at 22:51
  • The problem is the image is actually on different server. I've just read [something about SOP](https://developers.google.com/web-toolkit/doc/1.6/FAQ_Server?hl=sk#What_is_the_Same_Origin_Policy,_and_how_does_it_affect_GWT?), but I still don't know how to solve it. – DropDropped Nov 17 '12 at 22:56
  • I assume you want to avoid downloading the image if it has not changed? Otherwise, you could draw the old and new image to a canvas and compare the image data... That would be quite slow, though. And I am not sure whether drawing a foreign image prevents access to the pixel data... Didn't find anything about this in the spec. – Stefan Haustein Nov 17 '12 at 23:08

1 Answers1

1

It can be due to SOP as you wrote in comment. You can create php function and then call this function from GWT.

Community
  • 1
  • 1
Krivers
  • 1,986
  • 2
  • 22
  • 45