Thursday, November 9, 2017

Re: XMLHttpRequest getResponse instead of getResponseText to get arraybuffer data

I'd suggest maybe using XMLHttpRequest directly then; either the one in com.google.gwt.xhr, or the one in Elemental2; and if responseURL is missing (as in com.google.gwt.xhr case), then because it directly maps to the JS object (no encapsulation) you can use JsInterop or JSNI to access the property.

On Thursday, November 9, 2017 at 3:20:33 PM UTC+1, Mail Drafter wrote:
Thomas,

I was wondering if you could advise how one might access the responseURL property that I can see in a Response object in the inspector.
This is the final url from redirects when you access, for example, a google drive image.
One could use these urls as permalinks to their drive images. (Not what Google want I guess).

Ian

On Monday, 4 June 2012 23:59:35 UTC+10, Thomas Broyer wrote:


On Monday, June 4, 2012 2:53:28 PM UTC+2, Magallo wrote:
Hi, I tried to use your solution. Looking at Google I/O on youtube (http://www.youtube.com/watch?v=NNmoEOpGJdk) I saw this but I wasn't able to do it.

I tried creating this:

public class BinaryXMLHttpRequest extends XMLHttpRequest
{
    public native JavaScriptObject getResponse()
    /*-
    {
        return this.response;
    }
    -*/;
   
    //Set to "arraybuffer" or "blob" for binary response
    public native void setResponseType(String value)
    /*-
    {
       this.responseType = value;
    }
    -*/;
}

then I used this class this way:

BinaryXMLHttpRequest binxhr = (BinaryXMLHttpRequest)BinaryXMLHttpRequest.create();
binxhr.open("GET", "myservlet_url");
binxhr.setResponseType("arraybuffer");
       
binxhr.setOnReadyStateChange(new ReadyStateChangeHandler()
{
    @Override
     public void onReadyStateChange(XMLHttpRequest xhr)
     {
         BinaryXMLHttpRequest binxhr = (BinaryXMLHttpRequest)xhr;
         if( binxhr.getReadyState() == XMLHttpRequest.DONE )
         {
             binxhr.clearOnReadyStateChange();
             binxhr.getResponse(); => what can I do with this?
         }
    }
});

If you look, at the end I have a binxhr.getResponse(); But this function returna a JavaScriptObject type. What can I do now with this? This is not a byte[] or whatever, so, I don't know in GWT how to manipulate it. Do you have an idea?

It will be an ArrayBuffer, so you'd have to build a JSO overlay type representing ArrayBuffer and cast() the JSO to your ArrayBuffer.

But honestly, it'd be easier to compile GWT from trunk and use the API that's already in there. When 2.5 will be out the doors, simply replace your home-built pre-2.5 GWT with the official 2.5.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment