我正在将文件上传到其余服务器,并且必须将其转换为二进制格式,但它总是会给我带来格式错误的异常。
我在html页面上的代码是:
<input type="file" ngf-select="upload($file)">
角度模块中的依赖关系:
var app = angular.module('app', ['ngRoute',
'app.filters',
'app.services',
'app.directives',
'app.controllers',
'ui.bootstrap',
'ngCookies',
'angularFileUpload',
'ngFileUpload']);
依赖关系在控制器中:
app.controller("elasticSearchController",['$scope','$rootScope','$http','Upload',function($scope,$rootScope,$http,Upload)
代码用于上传到特定网址:
$scope.upload = function (file) {
var createIndexUrl='http://'+$rootScope.elasticSearch.url+':9200/'+$rootScope.elasticSearch.indexName+'/'+$rootScope.elasticSearch.typeName+'/'+$rootScope.elasticSearch.id+'?pretty='
Upload.upload({
url: createIndexUrl,
data: {file: file}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status + " "+resp.data);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
任何人都可以帮助我吗????