Angularjs 如何在文件上传方法中添加附加参数并在控制器端获取?

Angularjs 如何在文件上传方法中添加附加参数并在控制器端获取?,angularjs,file-upload,xmlhttprequest,Angularjs,File Upload,Xmlhttprequest,文件添加一些参数: angular.forEach(files, function (file) { file.DocumentType = xxxxxx; file.userDetails = xxxxxxxxxxxxx; this.uploadedIdFiles.push(file); }.bind(this)); 服务端代码: function FileUpload() { return $http({ method: 'Post',

文件添加一些参数:

angular.forEach(files, function (file) {
    file.DocumentType = xxxxxx;
    file.userDetails = xxxxxxxxxxxxx;
    this.uploadedIdFiles.push(file);
}.bind(this));
服务端代码:

function FileUpload() {
    return $http({
        method: 'Post',
        url: urlconfig.resourceserviceuri + '*FileUpload*',
        data: { file: this.uploadedIdFiles }
    }).then(function (response) {
        return response;
    }).catch(function (response) {
        return response;
    });
};

如何为DocumentTypeuserDetails

上的特定参数获取控制器端有两种方法可以通过文件上载添加附加信息:

  • 添加标题
  • 添加URL参数
  • 函数文件上传(文件){
    var headers={'Content-Type':file.Type};
    var params={'userDetails':JSON.stringify(file.userDetails)};
    var config={headers,params};
    返回$http.post(url、文件、配置);
    }
    
    浏览器方法无法将文件作为JavaScript对象的属性发送。在尝试上载其他属性之前,请先了解如何上载文件。我正在上载方法中添加多个文件。如何添加参数和标题