Javascript 如何在浏览器中本地保存拖动的图像
我是angular的新手,在github上使用angular文件上传项目 在我的一个应用程序中。到目前为止,后端还没有准备好,我希望删除的文件显示在浏览器本地。有办法吗 视图的我的代码:Javascript 如何在浏览器中本地保存拖动的图像,javascript,angularjs,upload,Javascript,Angularjs,Upload,我是angular的新手,在github上使用angular文件上传项目 在我的一个应用程序中。到目前为止,后端还没有准备好,我希望删除的文件显示在浏览器本地。有办法吗 视图的我的代码: <div ng-controller="MyCtrl"> <input type="file" ng-file-select="onFileSelect($files)"> <div class="button" ng-file-select="onFileSelect($
<div ng-controller="MyCtrl">
<input type="file" ng-file-select="onFileSelect($files)">
<div class="button" ng-file-select="onFileSelect($files)" data-multiple="true"></div>
<div id="image_drop_box" ng-file-drop="onFileSelect($files)" ng-file-drag-over-class="optional- css-class-name-or-function" ng-show="dropSupported">drop files here</div>
<div ng-file-drop-available="dropSupported=true" ng-show="!dropSupported">HTML5 Drop File is not supported!</div>
<button ng-click="upload.abort()">Cancel Upload</button>
</div>
把文件放在这里
HTML5删除文件不受支持!
取消上传
控制器中的逻辑如下所示:
.controller('MyCtrl', function($scope){
$scope.onFileSelect = function($files) {
//$files: an array of files selected, each file has name, size, and type.
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
$scope.upload = $upload.upload({
//upload logic
});
}
};
});
.controller('MyCtrl',函数($scope){
$scope.onFileSelect=函数($files){
//$files:选定文件的数组,每个文件都有名称、大小和类型。
对于(变量i=0;i<$files.length;i++){
var file=$files[i];
$scope.upload=$upload.upload({
//上传逻辑
});
}
};
});
您可能可以将base64字符串存储在中您可能可以将base64字符串存储在中您可能可以将base64字符串存储在中您可能可以将base64字符串存储在中
Convert the image into Base64 code and after that put the Base64 code in the src of imageg tag.
And to convert Image into Base64 in angular I would recommend you to use
[https://github.com/ninjatronic/angular-base64]
After following instructions for using this library, you can simply call:
var imageData=$base64.encode(image);
Don't forget to inject in your module:
.module('myApp', ['base64'])