Angular-FileUploader 1.x.x - 将表单数据添加到项目

时间:2015-12-03 13:53:27

标签: angularjs http file-upload form-data angular-file-upload

您好无法弄清楚如何使用angular-fileuploader将formdata添加到我的上传请求中

尝试使用onBeforeUploadItem,但它不添加数据:/

控制

   .controller('uplCtrl', function ($scope, $modalInstance, FileUploader) {

        var uploader = $scope.uploader = new FileUploader({
            url: 'xxxxxxxxxxxxxxx',
        });

        uploader.onBeforeUploadItem = function(item) {
            item.formData.push({some: 'data'});
        };
 });

在前端我只使用uploader="uploader" multipleuploader.uploadAll()

上传很好,但不会添加我的自定义表单数据

1 个答案:

答案 0 :(得分:0)

我认为这可能对你有所帮助。

角度控制器:

.controller('uploadCtrl', function ($scope, FileUploader) {
    $scope.uploader = new FileUploader({
        url: "./api/file/upload",
        formData: [
            { "data1": "value1" },
            { "data2": "value2" }
        ]
    });
});

在服务器端(在FileController中,方法:上传):

var provider = GetMultipartProvider();
var result = await Request.Content.ReadAsMultipartAsync(provider);

var data1 = result.FormData.Get("data1");
var data2 = result.FormData.Get("data2");