NG文件上传其他数据



我想将我的上传文件添加到我发送到Java Backend的另一个数据中。当我必须将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;
});
}

这是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);
    });
};

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

使用content-type:multipart form/data&使用form-data;请查看此链接https://developer.mozilla.org/en-us/docs/web/api/formdata/using_formdata_objects

最新更新