Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The current implementation of FileTransfer in PhoneGap makes this tricky, but it is possible. The problem is the format of <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2" rel="nofollow">multipart/form-data</a> in the post. For the server to correctly interpret a parameter as multi-valued, the raw request payload needs to have a series of Content-Disposition lines with the same name , like this:</p> <pre><code>--AaB03x Content-Disposition: form-data; name="shareWith[]" Joe --AaB03x Content-Disposition: form-data; name="shareWith[]" Jim --AaB03x Content-Disposition: form-data; name="shareWith[]" Jane </code></pre> <p>The array notation in the name indicates that the parameter is multi-valued, and the server will interpret this parameter as an array of values, the way you want.</p> <p>Unfortunately, this is the Objective-C code in the Cordova libs that appends the data to the request payload:</p> <pre><code> NSDictionary* options = [arguments objectAtIndex:5 withDefault:nil]; ... for (NSString* key in options) { ... [postBodyBeforeFile appendData:[[NSString stringWithFormat: @"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; </code></pre> <p>All it does is iterate through your params object (it expects a JS object like <code>{ param1: 'one', param2: 'two' }</code>) and pass each param object key to the key in this method call. It's not smart enough to check to see if the value is an array and if so, append multiple Content-Disposition lines - as you can see from the for statement, it assumes that each key is a string only. And because the options dictionary can't have multiple values with the same key, the form can't be created with Content-Disposition lines with the same name, the way you'd need to to submit multi-valued parameters.</p> <p>However, you should be able to achieve what you want in a less-than-elegant way by building the form names yourself, like this:</p> <pre><code>params = {} params['shareWith[0]'] = 'Joe'; params['shareWith[1]'] = 'Jim'; params['shareWith[2]'] = 'Jane'; </code></pre> <p>The result on the server may be a little different from the above, but this should get you most of the way there. Hopefully this will be addressed in the future and you'll be able to use multi-valued parameters a little more rationally with FileTransfer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload