angular-ui / ui-utils

Deprecated collection of modules for angular
http://angular-ui.github.io
MIT License
1.43k stars 546 forks source link

Ui uploader data #401

Closed ghost closed 9 years ago

ghost commented 9 years ago

ui-uploader not supported additional parameters to the upload POST request.

Variable named "data" is declared in the beginning og "ajaxUpload" function.

function ajaxUpload(file, url) {
        var xhr, formData, prop, data = '',
            key = '' || 'file';

Later on in this function, there is a code that check if data not empty, to add all its properties to the formData object as request parameters (POST variables...)

        // Append additional data if provided:
        if (data) {
            for (prop in data) {
                if (data.hasOwnProperty(prop)) {
                    formData.append(prop, data[prop]);
                }
            }
        }

But there is no way to populate this variable with data (the if statement in the previous example will never evaluate as "true").

As a result, the only way to add parameters to the upload request is using the query string (changing the URL) instead of using request body.

The solution (without breaking backword compitability) is to add 3rd argument "data" to "ajaxUpload". This argument is populated from "options.data".

PowerKiKi commented 9 years ago

Thanks a lot