Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angular js:通过http post请求上载包含多部分/表单数据的文件_Javascript_Jquery_Angularjs_Node.js_Multer - Fatal编程技术网

Javascript angular js:通过http post请求上载包含多部分/表单数据的文件

Javascript angular js:通过http post请求上载包含多部分/表单数据的文件,javascript,jquery,angularjs,node.js,multer,Javascript,Jquery,Angularjs,Node.js,Multer,我正在做多个文件上传。首先与您分享使用的技术。前端:angular js,后端:node js。当我使用下面的代码时,它对我来说很好 <form id="uploadForm" action="http://localhost:3000/api/policy/upload/file" enctype="multipart/form-data" method="post"> Choose file <input type="file" id="pdfInp" mu

我正在做多个文件上传。首先与您分享使用的技术。前端:angular js,后端:node js。当我使用下面的代码时,它对我来说很好

<form id="uploadForm" action="http://localhost:3000/api/policy/upload/file" enctype="multipart/form-data" method="post">
    Choose file
    <input type="file" id="pdfInp" multiple onchange="angular.element(this).scope().setFiles(this)" file-model="myFile" name="uploadedFiles">
    <input type="submit" value="Upload Image" name="submit">
</form>

选择文件
我正在使用multer上传节点js中的文件。但是,每当我通过调用函数而不是使用action属性来执行相同的操作时,它都会失败。我的角度代码如下,在提交时调用

<form id="uploadForm" ng-submit="uploadFile(myFile);" enctype="multipart/form-data" method="post">
    Choose file
    <input type="file" id="pdfInp" multiple onchange="angular.element(this).scope().setFiles(this)" file-model="myFile" name="uploadedFiles">
    <input type="submit" value="Upload Image" name="submit">
</form>

$scope.uploadFile = function (files) {
    var fd = new FormData();
    fd.append('file', files);
    $http.post('http://localhost:3000/api/policy/upload/file', fd, {
        transformRequest: angular.identity,
        headers: {
            'Content-Type': undefined,
        }
    }).success(function (result) {
        console.log(result);
    }).error(function(result){
        console.log(result);
    })
}

选择文件
$scope.uploadFile=函数(文件){
var fd=新FormData();
fd.append('file',files);
$http.post('http://localhost:3000/api/policy/upload/file,fd{
请求:angular.identity,
标题:{
“内容类型”:未定义,
}
}).成功(功能(结果){
控制台日志(结果);
}).错误(函数(结果){
控制台日志(结果);
})
}

请帮助我。为什么调用函数时不上载文件,请通过formdata传递文件。提前感谢。

我看到您使用的是非常旧的
ng model instant
(请参见)…您可以指定您使用的是哪个版本的angularjs吗?是的,这是错误的…我们可以删除它..顺便说一句,我使用jsv1.4.8是如何解决的?我在同一点上被卡住了:(@ranjitsingh你能把
文件的内容放进去吗
?我只是想看看它是否有效。我看到你使用的
ng model instant
非常旧(请参阅)…你能指定你使用的是哪个版本的angularjs吗?是的,这是个错误…我们可以删除它..顺便说一句,我使用jsv1.4.8你是如何解决的?我在同一点上被卡住了:(@ranjitsingh你能把
文件的内容放进去吗
?我只是想看看它是否有效。