我正在尝试使用meanjs实现danialfarid 的 angularjs-file-upload。但它不起作用。
是否可以将它与meanjs一起使用?
我正在尝试使用meanjs实现danialfarid 的 angularjs-file-upload。但它不起作用。
是否可以将它与meanjs一起使用?
你应该可以使用它,看起来你错过了将 angularjs-file-upload 模块包含到项目中的步骤,所以这里是在 MeanJS 应用程序中包含这个模块或任何外部 angular 模块的步骤:
1- 安装 angularjs-file-upload 文件上传后通过 bower 使用以下命令:
bower install ng-file-upload --save
2-你应该在你的应用程序布局页面中添加引用 angularjs-file-upload.js 文件,这是在文件中完成的:config\env\all.js,你应该有这样的行:
assets: {
lib: {
css: [
'public/lib/bootstrap/dist/css/bootstrap.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.css'
],
js: [
'public/lib/ng-file-upload/angular-file-upload-shim.min.js',
'public/lib/angular/angular.js',
'public/lib/ng-file-upload/angular-file-upload.min.js',
3-那么你应该在你的角度应用程序中包含 angularjs-file-upload 作为依赖项,这是在文件中完成的:public\config.js,在这一行的数组末尾添加“angularFileUpload”:
var applicationModuleVendorDependencies = ['ngResource', 'ngCookies', 'ngAnimate', 'ngTouch', 'ngSanitize', 'ui.router', 'ui.bootstrap', 'ui.utils', 'angularFileUpload'];
4-您现在应该可以在您的视图中使用文件上传器,如果还没有完成下一步,请再试一次。
5-如果你想在你的控制器中使用 angularjs-file-upload 服务,你应该在你的模块注册中注入上传服务( $upload ),如下所示:
angular.module('myModuleName').controller('MyController', ['$scope', '$stateParams', '$location', 'Authentication', '$upload',
function ($scope, $stateParams, $location, Authentication, $upload) {
// your controller code goes here
});
6-现在你应该是苹果在你的角度控制器中使用来自 angularjs-file-upload 的 $upload 服务,如下所示:
$upload.upload({
url: '/serverRouteUrl', //upload.php script, node.js route, or servlet url
method: 'POST', //Post or Put
headers: {'Content-Type': 'multipart/form-data'},
//withCredentials: true,
data: JsonObject, //from data to send along with the file
file: blob, // or list of files ($files) for html5 only
//fileName: 'photo' // to modify the name of the file(s)
}).success(function (response, status) {
//success
}
).error(function (err) {
//error
}
);
这将全部来自客户端,而不是您必须配置服务器端应用程序或路由才能处理文件上传请求,使用像Multer这样的库就可以了。