【问题标题】:Windows Phone 8 downloading files from webWindows Phone 8 从 Web 下载文件
【发布时间】:2013-11-28 09:16:44
【问题描述】:

我们正在使用 java/spring 开发移动 Web 应用程序,但在 Windows Phone 8 上下载 pptx、xls 等文件时遇到问题。

在 HTML 中,我们有这样的简单代码。

<div>
<a class="attchLink ui-link" target="_blank" href="/rest/item/DOCID159636/attachment/presentation.pptx">presentation.pptx</a>
</div>

在我们测试过的所有手机(iPhone 4S、5、Samsung Galaxy 4、mini、Windows phone 7)上,它运行良好,但在带有 Windows Phone 8 的诺基亚上,我们有时会卡在图标上 Tab 以打开 下载文件后显示女巫。 PPTX 文件大约有 500KB,所以文件大小不会有问题,而且有时手机(15%)会打开它。

有人知道这个问题是可以解决的还是只是 Windows phone 8 中 Microsoft 方面的错误?

【问题讨论】:

    标签: java html spring windows-phone-8 mobile-website


    【解决方案1】:

    您可能错过了在下载的 http 标头中设置文件的内容大小。

      @RequestMapping(value = "download/{id}", method = RequestMethod.GET)
      public HttpEntity<byte[]> download(@PathVariable("id") int documentId) {
    
             /* or how ever you access the content */
             byte[] content = this.documentService.loadDocumentContent(documentId)
    
             HttpHeaders headers = new HttpHeaders();
             headers.setContentType( /* depending on your document */ );
    /* -> */ headers.setContentLength(content.length); /* <-- that's the point */  
             headers.set("Content-Disposition", "attachment; filename=\"test.ppt\"");
    
             return new HttpEntity<byte[]>(content, headers);
    }
    

    【讨论】:

    • 来自 rest api 的响应看起来像 Status Code: 200 OK Cache-Control: max-age=0, no-cache, no-store Content-Length: 791775 Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Date: Thu, 28 Nov 2013 09:37:46 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Server: Apache-Coyote/1.1 它可以到最后一个字节。
    • 我们设置了内容长度,但在同一文件上尝试 100 次后,它仍然只能工作一次...
    • 我们正在通过 @ResponseBody 注释添加这个标题,它们看起来很好......我尝试像在你的示例中那样手动设置它们,它也没有帮助......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    相关资源
    最近更新 更多