Web Connection
ng-file-upload and GetMultipartFiles( Key )
Gravatar is a globally recognized avatar based on your email address. ng-file-upload and GetMultipartFiles( Key )
  Harvey Mushman
  All
  May 10, 2017 @ 07:37am

Compatibility Reference

When retrieving more than one file passed by the AngularJS ng-file-upload module by Danial Farid, the form data by default is passed as an array with a prefix key followed by a reference to an array element.

Content-Disposition: form-data; name="file[0]"; filename="Notes1.txt"

Content-Disposition: form-data; name="file[1]"; filename="Notes2.txt"

So the call to get the files is as follows:

loFiles = Request.GetMultipartFiles('file')

Problem is when Request parses the form data, the Key is not considered a prefix such as that described Request.aFormVars(@Vars,lcPrefix) where the prefix is more of a text string followed by a wildcard (i.e.: 'file*').

Solution:

As described deep in the documentation for ng-file-upload, formatting the key can be controlled for server implementation. This is done by adding the keyword arrayKey (camel case as shown) to the object in the upload method.

            Upload.upload({
                url: 'callback36.wcsx',
                fields: oFileFlds,
                arrayKey: '',
                file: files
            }).then(function (response) {

In Web Connection, REQUEST.GetMultipartFiles('file') works as intended when ng-file-upload arrayKey is an empty string as shown above.

Wa-hoo - it works!

Gravatar is a globally recognized avatar based on your email address. re: ng-file-upload and GetMultipartFiles( Key )
  Rick Strahl
  Harvey Mushman
  May 10, 2017 @ 10:54am

You know there are examples of how to do this in the samples, including multi-file uploads.

And just another hint - you'll want to probably use the new GetMultipartFiles() Response object method which gives you a collection that's easier to work with. All the array functions have been updated with cleaner Collection based versions. Things like GetFormVarCollection().

+++ Rick --

Gravatar is a globally recognized avatar based on your email address. re: ng-file-upload and GetMultipartFiles( Key )
  Harvey Mushman
  Rick Strahl
  May 11, 2017 @ 05:39am

Newer...? Than what version, I'm already running 6.x (4/2/2016) and using both of those methods. I think I'm only one version back.

© 1996-2024