NG 文件上传与另一个数据

Ng file upload with another data

我想通过 ng-file-upload 将我上传的文件添加到我发送到我的 Java 后端的另一个数据中。当我必须将 url 放入我的 .upload 时,我想知道该怎么做。在这种情况下无法工作导致 sendMail 首先发送文件,然后发送文本数据。我该如何解决?

$scope.sendMail = function(){   

$scope.uploadFiles = function(file) {
    $scope.attach = file;
    file.upload = Upload.upload({
        data: {file: file} 
    });
}

$scope.emailData = new EmailData();
$scope.emailData.to = "myMail@a.com";       
$scope.emailData.from = "yourMail@a.com";
$scope.emailData.type = "TYPE";
$scope.emailData.title = $scope.data.title;
$scope.emailData.descr = $scope.data.description;
$scope.emailData.template = "template";
$scope.emailData.file = $scope.attach;

$http.post("sendemail", $scope.emailData, {headers: {'Content-Type': 'application/json'} })
.then(function (response) {         
    $scope.succes =  true;
},
function(fail) {
    $scope.error = true;
});
}

使用内容类型:多部分 form/data & 使用表单数据;看看这个 link https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects

这是来自 ng-file-upload 的例子Github

$scope.upload = function (file) {
    Upload.upload({
        url: 'upload/url',
        data: {file: file, 'username': $scope.username}
    }).then(function (resp) {
        console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
    }, function (resp) {
        console.log('Error status: ' + resp.status);
    }, function (evt) {
        var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
        console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
    });
};

如你所见,你可以在数据中发送你想要的内容