const fileReader = new FileReader();
fileReader.onload = () => {
const link = <HTMLAnchorElement>windowService.document.createElement("a");
link.href = fileReader.result;
link.setAttribute("download", fileName);
link.target = "_blank";
windowService.document.body.appendChild(link);
link.click();
};
fileReader.readAsDataURL(testFile);
}
其中testFile是数据的二进制大对象(blob)。这段代码在所有浏览器和iOS应用程序中都可以正常运行,但在Android应用程序中无法正常工作。在Android WebView上,onDownloadListener函数被调用,只设置了URL参数,没有设置其他参数。
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// url: set as base64 encoded content
// no other attribute is set. I understand content disposition can be used to get file name but that is not set either
}
}
我希望能够获取下载属性上分配给文件的文件名。如何检索相同的文件名? 我正在使用Android API 28进行测试。