Re: [Xsltforms-support] file uploads
Brought to you by:
alain-couthures
From: Conal T. <con...@gm...> - 2017-02-10 10:01:42
|
Thanks Tim, for your help! I have successfully added support for "form-data-post" submissions to XSLTForms and I've moved on to my next problem, which is this: The web service my form deals with expects me to post an XML document as a named parameter in the "multipart/form-data" format (which means using XForms submissions with method="form-data-post"). It expects a form-data parameter called "fileToConvert", containing my XML document (which I have in an XForms instance). I can do this when using an <xf:upload> to populate the submitted instance; I have an instance like this: <xf:instance id="uploaded-odd" xmlns=""> <ege-webservice-call> <fileToConvert xsi:type="xsd:anyURI"/> </ege-webservice-call> </xf:instance> ... and I have an <xf:upload> that is bound to the <fileToConvert> element. When the user selects a file to upload, the "file://" URI of that file is inserted into the fileToConvert element, and when the submission takes place, the CONTENT of that file is submitted in place of the URI. That all works sweetly. But that only works for content which has been set by an <xf:upload>. If I have an instance that contains the XML document I want to submit, I can't submit that entire document as a parameter, because the XForms specification says that only the "leaf" elements of my XML will be serialized as distinct parameters. I want to submit not the leaves, but the root (and the entire tree), of the document. It works with the <xf:upload> because <fileToConvert> contains only a text node (the file:// URI) and hence is a leaf. In general it seems to me that XForms' design is based on an expectation that you are either sending and receiving XML entities, or alternatively you are sending form parameters to legacy servers, but not a combination of both. So It seems to me, in order to send my XML as a form parameter, I need to serialize the XML first, and then submit the serialization. I was hoping that XForms would provide a custom "serialize()" function that would escape my XML as text, or that there'd be some other obvious way to fix this, but I haven't found anything. The only solution I can see is to use a recursive <xf:action> to walk my XML instance's tree, gradually serializing it into a text node in another instance, and then submit THAT instance. This seems awkward, but I'm sure it's possible, and I'll do it if no-one can suggest anything better! Ideas? Conal On 1 February 2017 at 06:57, Conal Tuohy <con...@gm...> wrote: > thanks Tim! > > What submission method did you use in ypur test? > > On 01/02/2017 3:20 am, "Tim Thompson" <tim...@gm...> wrote: > >> Hi, Conal, >> >> I'm not sure about the support for different serialization formats, but I >> did just test <xf:upload> with rev.638, and it worked for me (on Ubuntu): >> >> <xf:upload incremental="true" >> mediatype="application/xml" >> ref="instance('file-upload')/upload/file"> >> <xf:label>Select</xf:label> >> <xf:filename >> ref="instance('file-upload')/upload/file/@filename"/> <!-- >> Relative XPath doesn't seem to work here. --> >> </xf:upload> >> >> When I upload a file, the file contents are inserted into the <file> >> element in my "file-upload" instance, and I am able to POST the contents to >> a server. When I do an upload, I get a relative file name (no file:///). >> >> Hope this helps, >> Tim >> >> -- >> Tim A. Thompson >> Metadata Librarian (Spanish/Portuguese Specialty) >> Princeton University Library >> >> www.linkedin.com/in/timathompson >> ta...@pr... >> >> >> On Sun, Jan 29, 2017 at 9:02 AM, Conal Tuohy <con...@gm...> >> wrote: >> >>> I have had a lot of difficulty in getting a file upload to work, in >>> XSLTForms rev.638, on either Firefox 50.1.0 or Chrome 55.0.2883.87 on >>> Linux Mint. >>> >>> What I am trying to do is use an <xf:upload> to load a local XML file, >>> and submit it to a web service which will convert it into some other >>> format. The web service expects an HTTP POST, but I believe it is happy >>> with a serialization of "application/xml" or "multipart/form-data" and >>> possibly it may work with "multipart/related". I have tried the various >>> XForms methods "post", "form-data-post", and "multipart-post" without >>> success. >>> >>> I have tried a number of things. >>> >>> It appears to me that the "form-data-post" submission method is not >>> supported by XsltForms at all >>> >>> It seems (from reading the JS code) that the "multipart-post" IS >>> supported, however, it fails to correctly serialize my instance containing >>> the file:/// URI set by my xf:upload (the XML containing the URI is sent >>> instead of the content which the URI refers to, even though I have set the >>> xsi:type="xsd:anyURI"). The same problem happens with the "post" method. >>> >>> Is this known behaviour? I am puzzled because the W3 XForms 1.1 test >>> suite results at http://www.agencexml.com/xf >>> orms-tests/testsuite/XForms1.1/Edition1/driverPages/forms/XF >>> 11_TestSuite.xhtml indicate that "form-data-post" should work. >>> >>> I would appreciate any clarification about this is supposed to work, or >>> advice as to what functionality is missing. >>> >>> Thanks! >>> >>> >>> Conal >>> >>> >>> >>> -- >>> Conal Tuohy >>> http://conaltuohy.com/ >>> @conal_tuohy >>> +61-466-324297 <+61%20466%20324%20297> >>> >>> ------------------------------------------------------------ >>> ------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> Xsltforms-support mailing list >>> Xsl...@li... >>> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >>> >>> >> -- Conal Tuohy http://conaltuohy.com/ @conal_tuohy +61-466-324297 |