【问题标题】:Download data from URL with GWT使用 GWT 从 URL 下载数据
【发布时间】:2013-09-09 03:02:40
【问题描述】:

这是一个典型的 img,其中 src 有一个 blob:

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

有没有办法让我的 GWT 应用下载获取他的 blob 数据以进行客户端操作?

我试过这个:

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();
}-*/;

但是,当传递 blob 源时,警告框不显示,因此它不起作用。而this.status 的响应是0

【问题讨论】:

    标签: java javascript jquery gwt jsni


    【解决方案1】:

    可能是这样的

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

    单击按钮时,应使用提供的文件名下载文件。

    另一种方法是使用点击处理程序,它使用

    Window.open(url, "_blank", "menubar=no,status=no");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 2016-10-18
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多