Pregunta

This is a typical img with src having a blob:

<img class="gwt-Image" src="blob:a7cb8111-cf35-4c3a-8295-bdda0ff66caf">

Is there a way for my GWT app to download get his blob data for client side manipulation?

I've tried this:

private native String blobToBase64(String source)/*-{
    var xhr = new XMLHttpRequest();
    xhr.open('GET', source, true);
    xhr.responseType = 'blob';
    xhr.onload = function(e) {
      if (this.status == 200) {
        var myBlob = this.response;
        alert("Converted to Blob");
      }
    };
    xhr.send();
}-*/;

However, alert box does not show up when passed the blob source, so it does not work. And the this.status response is 0

¿Fue útil?

Solución

Perhaps something like

button.setAttribute("download", "filename.png");    
String url = "data:Application/octet-stream;base64," + blobAsBase64;
button.setHref(url);

When button is clicked the file should be downloaded with the provided file name.

Another way is to use a click handler and it use

Window.open(url, "_blank", "menubar=no,status=no");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top