我正在尝试上传图片并将其存储在存在数据库中,但打开存储的图片时出现下一个错误:
Cannot open specified file: Could not recognize image encoding.
我已经尝试了下一个代码,对普通的 txt 文件进行了小幅调整,它工作正常,但不适用于图片。
图片.xhtml
<?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<title/>
<xf:model>
<xf:instance xmlns="">
<data>
<image xsi:type="xs:base64Binary"/>
</data>
</xf:instance>
<xf:submission id="save" action="save.xquery" method="post"/>
</xf:model>
</head>
<body>
<xf:upload ref="image">
<xf:label>Upload Photo:</xf:label>
</xf:upload>
<br/>
<xf:submit submission="save">
<xf:label>Save</xf:label>
</xf:submit>
</body>
</html>
保存.xquery
xquery version "3.1";
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
let $login:=xmldb:login('xmldb:exist:///db/apps/places','admin','admin')
(: The small adjusment i refer is just to change file extension from .jpeg to .txt :)
return xmldb:store("/db/apps/places/",concat("pic",".jpeg"), util:base64-decode(request:get-data()//image))