2017-02-28 97 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); 

可能會對某人有幫助