我想让用户从服务器下载一个文件。我用抬头看作为解决方案,当我试图做一个例子时,最终得到了以下结果:
@Route("test-download")
public class Download extends VerticalLayout {
public Download() {
Anchor downloadLink = new Anchor(createResource(), "Download");
downloadLink.getElement().setAttribute("download", true);
add(downloadLink);
}
private AbstractStreamResource createResource() {
return new StreamResource("/home/johny/my/important-file.log", this::createExportr);
}
private InputStream createExportr(){
return null;
}
}
当我在浏览器中进入页面时,它会给出java.lang.IllegalArgumentException: Resource file name parameter contains '/'
。
如何使下载按钮(或锚)知道文件在磁盘上的位置?
发布于 2018-09-04 06:12:37
https://stackoverflow.com/questions/52150056
复制相似问题