[英]AngularJS photo/file upload
除了FF,在其他浏览器上上传文件和照片似乎效果很好。 它似乎在form.append的某个地方失败了,但是我不明白为什么它可以在Chrome和IE上运行,但不能在FF上运行。
有人可以照亮这一点吗?
控制器:
$scope.uploadProfilePhoto = function() {
$timeout(function(){
var form = new FormData();
form.append("fileName", vm.profilePhoto.fileName);
form.append('file', vm.profilePhoto.file);
ProfileService.uploadProfilePicture(form)
.then(function(response){
vm.ProfilePictureUrl = api.getQualifiedUrl('image/' + response.data.ImageId);
})
});
}
输入:
<label for="profilePhoto" class="photo-upd" >
<img data-ng-src="{{vm.ProfilePictureUrl}}" id="profile-picture_image" alt="Candidate profile photo" onchange="angular.element(this).scope().uploadProfilePhoto(this)" class="img-responsive">
<span><i class="fa fa-upload"></i> Upload Photo</span>
</label>
<input id="profilePhoto" type="file" name="profilePhoto" valid-file data-oh-file fileread="vm.profilePhoto.file" filename="vm.profilePhoto.fileName" class="hidden"onchange="angular.element(this).scope().uploadProfilePhoto(this)">
错误:
vm.profilePhoto is undefined
Profile/$scope.uploadProfilePhoto/
您不应该在上传功能中使用$ scope.vm吗?
我只是注意到vm
对象必须是对象或控制器的self
或this
。
并且您还需要声明vm.profilePhoto
对象:
var vm = this; vm.profilePhoto = {};
这里的例子:
https://jsfiddle.net/alvarojoao/v9rfn301/
var app = angular.module("turingApp", []);
app.controller("turingController", ["$scope","$timeout", function($scope,$timeout) {
var vm = this;
vm.profilePhoto = {};
$scope.uploadProfilePhoto = function() {
$timeout(function() {
var form = new FormData();
form.append("fileName", vm.profilePhoto.fileName);
form.append('file', vm.profilePhoto.file);
ProfileService.uploadProfilePicture(form)
.then(function(response) {
vm.ProfilePictureUrl = api.getQualifiedUrl('image/' + response.data.ImageId);
})
});
};
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.