【问题标题】:How to save a dragged image locally in the browser如何在浏览器本地保存拖动的图像
【发布时间】:2014-10-26 18:31:22
【问题描述】:

我是 angular 新手,在 github https://github.com/danialfarid/angular-file-upload 上使用 angular-file-upload 项目 在我的一个应用程序中。直到现在后端还没有准备好,我希望将删除的文件显示在本地浏览器中。有办法吗?

我的视图代码:

<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>

控制器中的逻辑如下所示:

.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 
      });
    }
  };
});

【问题讨论】:

    标签: javascript angularjs upload


    【解决方案1】:
    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'])
    

    【讨论】:

    猜你喜欢
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多