我正在使用此照片上传指令上传图片:
https://github.com/danialfarid/ng-file-upload
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
fields: {
'username': $scope.username
},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$scope.log = 'progress: ' + progressPercentage + '% ' +
evt.config.file.name + '\n' + $scope.log;
}).success(function (data, status, headers, config) {
$timeout(function() {
$scope.log = 'file: ' + config.file.name + ', Response: ' + JSON.stringify(data) + '\n' + $scope.log;
});
});
}
}
};
我需要添加“粘贴”功能。来自剪贴板的图像以及由ng-file-upload上传的图像。
有人能指点我怎么做吗?
答案 0 :(得分:2)
function handlePaste(e) {
$log.debug(e.originalEvent.clipboardData);
for (var i = 0 ; i < e.originalEvent.clipboardData.items.length ; i++) {
var item = e.originalEvent.clipboardData.items[i];
console.log("Item type: " + item.type);
if (item.type.indexOf("image") != -1) {
$log.debug( item.getAsFile(), {});
Upload.upload({file: item.getAsFile(),
url: '/upload/', //upload.php script, node.js route, or servlet url
// method: POST or PUT,
// headers: {'header-key': 'header-value'},
// withCredentials: true,
data: {user_uuid: $scope.session.user.user_uuid}});
} else {
alert("Discarding non-image paste data");
}
}
}
答案 1 :(得分:0)
粘贴图像与删除它们相同
<div class="img-dropper" ngf-drop="upload($files)" ng-model="context[terminatedkey]" ngf-drag-over-class="'dragover'" tabindex="0">
<span>Paste or drop files here</span>
</div>
,默认$scope.upload = function (file)
将起作用