2017-02-28 101 views
0

我在服务器模式下使用Appache Tika。 我需要开发java rest客户端来解析文件。 对于PDF文件上传我正在使用的代码:Apache Tika:通过Rest中的java解析docx

fileBody = new FileBody(file, "application/pdf"); 
multiPartEntity.addPart("uploaded_file", fileBody); 
pdfPutRequest.setEntity(multiPartEntity); 
response = client.execute(pdfPutRequest); 

使用apache.http库。 现在我尝试开发docx部分,但我不知道我需要提供哪个mimeType(application/docx给我错误)。 没有mimeTipe我收到Tika服务器中的“不支持的媒体类型”异常。 那么,我需要提供哪种类型,并且需要做其他一些更改。

解决了!

回答

0

.docx文件正式MIME类型

application/vnd.openxmlformats-officedocument.wordprocessingml.document 

如果您使用--detect模式蒂卡CLI工具它可以告诉你,

或者,蒂卡服务器具有可as documented in the Tika Server wiki检测模式。

最后,提卡将自动检测的MIME类型,你如果没有给出,请参阅the text extraction part of the Tika Server docs的信息上给予或不给一个MIME类型提示你文件

+0

谢谢你的回答。我已经看到了检测选项,并尝试了它。我在其他地方发现了问题...当我发送文件时,我使用了多个部分,但通过PUT请求完成了此操作...现在,我在文档中看到它应该通过POST发送... – user3558218

0

我找到了解决办法:

HttpPost docxPutRequest new HttpPost(url); 
docxPutRequest.setHeader("Accept", "text/plain"); 
MultipartEntity multiPartEntity = new MultipartEntity(); 
FileBody fileBody = new FileBody(file); 
multiPartEntity.addPart("uploaded_file", fileBody); 
docxPutRequest.setEntity(multiPartEntity); 
response = client.execute(docxPutRequest); 

可能会对某人有帮助