2015-06-23 104 views
0

我在Azure Blob存儲上存儲了所有不同類型的文件,文件是txt,doc,pdf等。然而,所有文件都存儲爲'octet-stream',當我打開文件以使用Tika從文本中提取文本時,Tika無法檢測字符編碼。我怎樣才能解決這個問題?如何使用Apache Tika解析八位字節流文件?

FileSystem fs = FileSystem.get(new Configuration());    
Path pt = new Path(Configs.BLOBSTORAGEPREFIX+fileAdd);   
InputStream stream = fs.open(pt);   


AutoDetectParser parser = new AutoDetectParser(); 
BodyContentHandler handler = new BodyContentHandler(); 
Metadata metadata = new Metadata(); 

parser.parse(stream, handler, metadata);  


spaceContentBuffer.append(handler.toString()); 

回答

1

如果直接調用Azure存儲REST API,你可以設置頁眉通過API Set Blob Properties 「X-MS-BLOB內容類型」。

blockBlob.Properties.ContentType = "text/xml"; 
blockBlob.SetProperties(); 
+0

我使用Azure存儲客戶端:

如果您正在使用Azure存儲客戶端庫,你可以寫如下類似的代碼。我編輯了我的帖子,以便您可以看到我的代碼。您能否考慮我的代碼向我提供更多解釋? –

相關問題