** Description changed:

  I was implementing some XQuery code for uploading a file and some form
  data. Fiddling with Multipart request and the http-client wasn't really
  usable, the http-client added some extra multipart content-type header
  and didn't work well. In the end I was implementing multipart requests
  manually:
  
- <http:body media-type = "multipart/form-data; 
boundary=----------------------------6d6f6d615f08" method = "binary">{
-       concat (
-         "------------------------------6d6f6d615f08&#13;&#10;",
-         'Content-Disposition: form-data; name="file"; 
filename="test.jpg"&#13;&#10;',
-         "Content-Type: multipart/form-data&#13;&#10;",
-         "&#13;&#10;",
-         base64:decode(file:read-binary ($filename)),"&#13;&#10;",
-         "------------------------------6d6f6d615f08&#13;&#10;",
-         'Content-Disposition: form-data; name="description"&#13;&#10;',
-         "&#13;&#10;",
-         "A test file&#13;&#10;",
-         "------------------------------6d6f6d615f08&#13;&#10;",
-         'Content-Disposition: form-data; name="category"&#13;&#10;',
-         "&#13;&#10;",
-         "main&#13;&#10;",
-         "------------------------------6d6f6d615f08--&#13;&#10;"
-       )
+ <http:body media-type="multipart/form-data; boundary=--6d6f6d615f08" 
+            method="binary">{
+       concat (
+         "----6d6f6d615f08&#13;&#10;",
+         'Content-Disposition: form-data; name="file";',
+         ' filename="test.jpg"&#13;&#10;',
+         "Content-Type: multipart/form-data&#13;&#10;",
+         "&#13;&#10;",
+         base64:decode(file:read-binary ($filename)),"&#13;&#10;",
+         "----6d6f6d615f08&#13;&#10;",
+         'Content-Disposition: form-data; name="description"&#13;&#10;',
+         "&#13;&#10;",
+         "A test file&#13;&#10;",
+         "----6d6f6d615f08&#13;&#10;",
+         'Content-Disposition: form-data; name="category"&#13;&#10;',
+         "&#13;&#10;",
+         "main&#13;&#10;",
+         "----6d6f6d615f08--&#13;&#10;"
+       )
  }</http:body>
  
  As this is not usable for common users, I propose 2 changes:
  
  1. the multipart implementation of the http client can be done in XQuery only 
(see example above) which would make this implementation more stable
  2. a helper module where one just passes an html form and gets an http 
request for execution, for example:
  
- html-forms:create-request(
-   <form action="http://www.example.com/upload"; method="post" 
enctype="multipart/form-data">
-      <input name="file" type="file" value="{$filename}" />
-      <input name="description" type="text" value="A test file">
-      <input name="category" type="text" value="main">
-   </form>
+ http-client:send-request(
+   html-forms:create-request(
+     <form action="http://www.example.com/upload"; 
+           method="post" 
+           enctype="multipart/form-data">
+        <input name="file" type="file" value="{$filename}" />
+        <input name="description" type="text" value="A test file">
+        <input name="category" type="text" value="main">
+     </form>
+   )
  )

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/996793

Title:
  using http-client to execute an html form

Status in Zorba - The XQuery Processor:
  New

Bug description:
  I was implementing some XQuery code for uploading a file and some form
  data. Fiddling with Multipart request and the http-client wasn't
  really usable, the http-client added some extra multipart content-type
  header and didn't work well. In the end I was implementing multipart
  requests manually:

  <http:body media-type="multipart/form-data; boundary=--6d6f6d615f08" 
             method="binary">{
        concat (
          "----6d6f6d615f08&#13;&#10;",
          'Content-Disposition: form-data; name="file";',
          ' filename="test.jpg"&#13;&#10;',
          "Content-Type: multipart/form-data&#13;&#10;",
          "&#13;&#10;",
          base64:decode(file:read-binary ($filename)),"&#13;&#10;",
          "----6d6f6d615f08&#13;&#10;",
          'Content-Disposition: form-data; name="description"&#13;&#10;',
          "&#13;&#10;",
          "A test file&#13;&#10;",
          "----6d6f6d615f08&#13;&#10;",
          'Content-Disposition: form-data; name="category"&#13;&#10;',
          "&#13;&#10;",
          "main&#13;&#10;",
          "----6d6f6d615f08--&#13;&#10;"
        )
  }</http:body>

  As this is not usable for common users, I propose 2 changes:

  1. the multipart implementation of the http client can be done in XQuery only 
(see example above) which would make this implementation more stable
  2. a helper module where one just passes an html form and gets an http 
request for execution, for example:

  http-client:send-request(
    html-forms:create-request(
      <form action="http://www.example.com/upload"; 
            method="post" 
            enctype="multipart/form-data">
         <input name="file" type="file" value="{$filename}" />
         <input name="description" type="text" value="A test file">
         <input name="category" type="text" value="main">
      </form>
    )
  )

To manage notifications about this bug go to:
https://bugs.launchpad.net/zorba/+bug/996793/+subscriptions

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to