Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Motivation

The upload element allows you to select a file from the file system using your operating system's "Browse" user interface. This file can then be transferred to the file server that the web form resides.

Screen Image

Here is a screen image of the Firefox XForms extension upload control after the C:\tmp\Foo.xml file was selected:

(Image: Eddy Chaverra, CC BY-SA 3.0)

The XForms upload Element

ref="XPathExpression" mediatype="text/xml">
ref="XPathExpression" />
ref="XPathExpression" />

Sample Program

This sample program has a single instance variable called "File". At the end of the select this variable is set to the path-name of the file you just selected.

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>

xmlns="">

xsi:type="xs:anyURI"/>

ref="/Data/File">
file:///C:/tmp/*.xml
text/xml

ref="/Data/File">
File:

Discussion

At the time of this writing, there is little documentation on how the upload control works. The screen shot above was taken from the Firefox XForms 0.8 running on Firefox 3 implementation. Note that the file name appears twice in the control itself. This may not be the future behavior. This may be that the filename and mediatype text inside the control are being displayed. There is no documentation yet on how to disable the clear trigger.

There is not yet documentation on how to upload instance data into the model using the upload control. Right now instance data must be hard-coded into the src attribute of an instance.

The following loads both an image and a URI.

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">

xmlns="">

xsi:type="xs:base64Binary"/>
xsi:type="xs:anyURI"/>

id="save" action="http://xformstest.org/cgi-bin/showinstance.sh" method="post"/>

ref="image">
Upload Photo:

ref="uri">
Upload File:
file:///C:/tmp/*.xml
text/xml

ref="image">
image:

ref="uri">
uri:

submission="save">
Save

Uploading Binary Files

Any file type such as an image or XML file can be converted to a 64bit encoded file, stored in the instance and then transmitted to the server inside of a POST. On the server the file can be converted back to a string or binary.

Sample Echo With Binary to String Unencoding

The following is a simple echo script written in XQuery that echos back the binary file in XML. It is an XQuery script
that uses a binary-to-string conversion function. This takes a file of type xs:base64binary and returns a string
representation of the file. The data to be returned is in the element with the element name "xml-base64".

xquery version "1.0";
declare option exist:serialize "method=xml media-type=text/xml indent=yes";

(: this gets the data from the HTTP POST :)
let $post-data := request:get-data()
(: this converts the base-64 binary to a plaintext string that holds the unparsed XML content :)
let xml-as-string := util:base64-decode(post-data//xml-base64)
let parsed-xml := util:parse(xml-as-string)

return

{$xml-as-string}
{$parsed-xml}

Sample Form

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>

Upload XML

xmlns=''>

xsi:type="xs:base64Binary"/>

id='post-to-echo'
action='echo-base64-binary.xq' replace="all"
method='post'/>

ref="xml-base64">
Upload XML File:

ref="xml-base64">
XML file encoded in base64binary:

submission="post-to-echo">
Post to Echo

Sample File

This is a small XML file.

Warnings

The attribute data type assignment xsi:type="xs:anyURI" must be associated with the variable used to store the file path name.

References

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
Using a trigger abstraction allows your XForms to be more portable. ## Sample Program xmlns=" xmlns:xf=" xmlns:ev=" > Button Example xmlns=""> Button If you press this you will get a hello world message. level="modal" ev:event="DOMActivate">Hello World! ## Discussion This example has both a label an
CC BY-SA 4.0
This example demonstrates how to control the button appearance using labels, hint text and images. To see the button images appear you will need to create a file called XForms-button.jpg in the folder that this program is executed from. This example requires an image to be used in the program. This
CC BY-SA 4.0
It allows the user to select a numeric value from a range of values without using the keyboard. This is ideal for instructors that use interactive learning environments such as a SmartBoard. The XForms range has four attributes: - **start** - the lower bound of the range - **end** - the upper bound
CC BY-SA 4.0
This must be the ID of one of the submission elements in your model. Here is and example: submission="get-additional-data"/> If you reference this submission you will need a corresponding submission in your model. id="get-additional-data" .../> ## Common Usage The most common usage of send is to per
CC BY-SA 4.0
Show can have two values: **new** or **replace**. - **target** - the target action to be executed One is the URI of the resource to load and the other is the show attribute. The show attribute can have values of "replace" which will replace the current form with the new resource and "new" which will
CC BY-SA 4.0
On many HTML forms you fill out the form and press a button at the bottom of the form called "Save" or "Submit". You pressed the button and hoped your data would get saved. This is the same concept. But in this case the submit command can be triggered in many ways other that just a button being pres