下载多种文件类型
我正在使用 jsp servlet 来上传和下载文件。
我想下载多种类型的文件,因此我选择将它们下载为 zip 文件,以免在响应中定义每种类型的附件时,当我上传正确上传的所有文件时,当我下载 txt 和docx 文件它们也可以正确下载,但是当我下载 pdf 或图像文件时,它们没有正确下载,因为我将它们放在同一个文件夹中!
I am using jsp servlet to upload and download files.
I want to download many types of files, so I choose to download them as zip files in order not to fall in defining each type of attachment in the response, when I make upload all of files uploaded correctly, when I make download for txt and docx files they are downloaded correctly too, but when I download pdf or image files, they are not downloaded correctly, since I put them in the same folder!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实:
.txt
和.docx
(XML!)文件是基于文本的,而PDF和图像是基于二进制的。因此,听起来很像您使用
Reader
/Writer
而不是InputStream
/OutputStream
来读取/写入文件。相应地修复代码。只要您对基于字符的实际文件内容不感兴趣,就永远不要使用
Reader
/Writer
。它将完全损坏二进制文件。您可以在此处找到下载 servlet 的基本示例。Fact:
.txt
and.docx
(XML!) files are text based while PDF and images are binary based.So, it sounds much like that you read/write files using
Reader
/Writer
instead ofInputStream
/OutputStream
.Fix the code accordingly. Never use
Reader
/Writer
as long as you're not interested in the actual file content on a character basis. It will totally corrupt binary files. You can find a basic example of a download servlet here.