dwr - 在一个请求中上传文件和下载文件

发布于 2024-08-23 16:13:21 字数 74 浏览 6 评论 0原文

是否可以上传一个文件,然后在收到响应时下载该文件,

我的意思是在一个请求中,我将上传一个文件并在一个操作中下载该文件?

is it possible to upload a file and subsequently when receiving response download the file,

I mean in one request I'll upload a file and download the file in one action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

×纯※雪 2024-08-30 16:13:21

也许这个演示代码会对您有所帮助:
http://directwebremoting.org/dwr-demo/simple/download.html

Maybe this demo code will be helpful for you:
http://directwebremoting.org/dwr-demo/simple/download.html

硬不硬你别怂 2024-08-30 16:13:21

是的,至少在 dwr 3 中可以做到这一点。

Yes It's possible to do that at least in dwr 3.

魂牵梦绕锁你心扉 2024-08-30 16:13:21

返回 Excel 以从客户端下载的示例:

//Java 端:

public FileTransfer getExcel(Parametros param){
   byte[] result = <here get data>;
   InputStream myInputStream = new ByteArrayInputStream(result); 
   String excelFormat = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
   FileTransfer dwrExcelFile = new FileTransfer("excel.xlsx", excelFormat, myInputStream);
   return dwrExcelFile;
}

//Javascript 端:

function downloadExcelFile() {
  dwr.engine.setTimeout(59000);
  var params = <params_to_send>;
  <Java_class>.getExcel(params, {callback:function(dataFromServer) {
    downloadExcelCallback(dataFromServer);
  }});
}

function downloadExcelCallback(data) {
   dwr.engine.openInDownload(data);
}

An example which return a excel to download from client:

//Java side:

public FileTransfer getExcel(Parametros param){
   byte[] result = <here get data>;
   InputStream myInputStream = new ByteArrayInputStream(result); 
   String excelFormat = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
   FileTransfer dwrExcelFile = new FileTransfer("excel.xlsx", excelFormat, myInputStream);
   return dwrExcelFile;
}

//Javascript side:

function downloadExcelFile() {
  dwr.engine.setTimeout(59000);
  var params = <params_to_send>;
  <Java_class>.getExcel(params, {callback:function(dataFromServer) {
    downloadExcelCallback(dataFromServer);
  }});
}

function downloadExcelCallback(data) {
   dwr.engine.openInDownload(data);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文