简体   繁体   中英

ms word file download issue in servlet from unix server to windows

While uploading doc file (example test.doc) to server(unix machine), I am using apache commons jar which gives me FormFile instance at server side which is having all the data in byte array form.

When I write the same byte array to response output stream and send it to browser to download the same file, weird content is shown. I get one pop up to select encoding in which i would like to see the data and weird data is shown in that doc.The content type is set as follows :

response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename=test.doc");

I think that while writing data to output stream, meta data related to doc file is also written which causes this issue.

Is there anything specific for doc or docx file formats, which needs to be done so file is in proper format and i can see correct data which i uploaded or I am missing something?

Any help would be appreciated.

Thanks in Advance.

Let me know if more info is required.

Microsoft中存在一个已知问题,该问题为“ 编码弹出”提供了解决方法

It may not be a fix for your problem because I have not run any test around. But to check the correct mime types please refer to this link:

https://technet.microsoft.com/en-us/library/ee309278(office.12).aspx

Updated:

You can use response type as ArrayBuffer and set the content as Blob.

Blob([response], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'});

Or this could work

response.setContentType("application/x-msdownload"); response.setHeader("Content-disposition", "attachment; filename="+ fileName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM