Posted by
bsteuhl on
URL: https://discuss.orbeon.com/Decoding-base64Binary-tp25132p3852365.html
Erik,
I am have a mental block on something. I am uploading a document and storing it into MySQL database as base64Binary successfully using combination of xsl, url, identity and sql processor. I then want users to be able to download the document and I need to convert or decode the base64Binary and I thought this code would work but it just returns the same base64Binary stored in MySQL: So I grab the base64Binary data, wrap it in a document element with appropriate attributes, and then write that file to a temporary location grabbing the url back in the xForm for user to download. What part am I missing so that a PDF file stored as base64Binary can be opened back up as a PDF?
<p:config xmlns:p="
http://www.orbeon.com/oxf/pipeline" xmlns:sql="
http://orbeon.org/oxf/xml/sql" xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:oxf="
http://www.orbeon.com/oxf/processors" xmlns:xi="
http://www.w3.org/2001/XInclude" xmlns:fe="
http://example.com/forms/onViewArrest/xform" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"> <p:param type="input" name="instance"/>
<p:param type="output" name="data"/>
<p:processor name="oxf:sql">
<p:input name="data" href="#instance"/>
<p:input name="config">
<sql:config xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"> <sql:connection>
<sql:datasource>cjpsis</sql:datasource>
<sql:execute>
<sql:query>
select document from docs where incidentNumber = 'R4';
</sql:query>
<sql:result-set>
<tempFile>
<sql:row-iterator>
<sql:get-column-value type="xs:base64Binary" column="document"/>
</sql:row-iterator>
</tempFile>
</sql:result-set>
</sql:execute>
</sql:connection>
</sql:config>
</p:input>
<p:output name="data" id="file-data"/>
</p:processor>
<p:processor name="oxf:xslt">
<p:input name="data" href="#file-data"/>
<p:input name="config">
<xsl:stylesheet version="2.0">
<xsl:template match="/">
<document xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:base64Binary" content-type="binary/octet-stream">
<xsl:value-of select="."/>
</document>
</xsl:template>
</xsl:stylesheet>
</p:input>
<p:output name="data" id="dynamicFile"/>
</p:processor>
<p:processor name="oxf:file-serializer">
<p:input name="config">
<config>
<scope>session</scope>
</config>
</p:input>
<p:input nae="data" href="#dynamicFile"/>
<p:output name="data" ref="data"/>
</p:processor>
</p:config>
Brian Steuhl
BTM Software Solutions, LLC