我有一個Web服務運行在同一臺機器上作爲存在數據庫使用PDF(從數據庫爲base64),並返回PNG(作爲base64)使用httpclient。他們是一個相當於文件:serialize-binary存儲數據存在-db
一個簡單的例子的Xquery是:
xquery version "3.0";
let $testdata := util:binary-doc('/db/data/Customers/assets/logo.pdf')
let $url := "http://localhost:4802/Pdf2Img.aspx"
let $headers := <headers></headers>
let $b64response := httpclient:post(xs:anyURI($url),$testdata,false(),$headers)/httpclient:body/text()
return
file:serialize-binary($b64response,'D:\DataLoad\test.png')
這工作得很好。它將PNG圖像存儲在文件系統中沒有問題。
我在整個文檔中查找的內容基本上是相同的示例,但可以將解碼的$ b64response作爲二進制映像直接存儲到數據庫。我找不到任何函數來將base64解碼爲二進制文件,然後將該數據存儲在數據庫中。
現在,我知道我可以將這個寫入磁盤的文件注入到數據庫中,但我試圖避免這會導致的問題(如清理,多線程和命名)。
在你不知道的情況下,反應是這樣的:
<httpclient:response xmlns:httpclient="http://exist-db.org/xquery/httpclient" statusCode="200">
<httpclient:headers>
<httpclient:header name="Cache-Control" value="private"/>
<httpclient:header name="Transfer-Encoding" value="chunked"/>
<httpclient:header name="Content-Type" value="image/png"/>
<httpclient:header name="Server" value="Microsoft-IIS/10.0"/>
<httpclient:header name="X-AspNet-Version" value="4.0.30319"/>
<httpclient:header name="X-Powered-By" value="ASP.NET"/>
<httpclient:header name="Date" value="Wed, 26 Jul 2017 21:07:26 GMT"/>
</httpclient:headers>
<httpclient:body mimetype="image/png" type="binary" encoding="Base64Encoded">iVBORw0KGgoAAAANSUhEUgAABfIA .... snipped here
所以它都在那裏,我只是想好好HttpClient的:身體/文本(),並將其存儲,因爲它代表了PNG數據庫。
我在這裏錯過了什麼?
UPDATE我回答了我自己的問題與工作解決方案。
我想你在做什麼(基本UTIL:二進制到字符串()的響應,雖然它保存到數據庫中,該文件已損壞 –
在閱讀你的代碼,我不要以爲它會回答我的問題,內容以二進制形式返回(參見上文)type =「binary」和encoding =「Base64Encoded」。因此,您的代碼將採用base64的字符串並將其存儲在數據庫中,這正是如果我使用編輯器來檢查數據庫中的文件,我會看到base64編碼的數據,而不是二進制文件。 –
評論中的關鍵是響應不是圖像,它是一個base64編碼圖像。 –