2017-06-05 52 views
0

我tryng上传图片,并存储在存在-DB,但我得到下一个错误打开保存图片时:如何使用eXist-db上传和保存图片?

Cannot open specified file: Could not recognize image encoding.

我已经tryed下一个代码与一个小的调整正常TXT文件,它工作正常,但不与图片。

picture.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> 

save.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)) 
+2

我建议写信给betterform-user邮件列表https://lists.sourceforge.net/lists/listinfo/betterform-users。 – joewiz

回答

0

如果你想存储图像的存在,但分贝,你或许应该xmldb:store-as-binary()取代xmldb:store()