2014-09-11 162 views
0

我需要使用angularjs指令獲取完整文件名, Bellow是我的代碼,在這裏我只獲取文件名。是否有可能獲得完整的文件名?如何使用AngularJs獲取完整文件路徑(圖像文件)

<input type="file" fileread="justice.imageLocation" />

MyApp.directive('fileread', [function(){ return { scope: { fileread:"=" }, link: function (scope, element, attributes) { element.bind("change", function (changeEvent) { scope.$apply(function() { // I am getting file name here! scope.fileread = changeEvent.target.files[0].name; }); }); } } }]);

回答

0

我知道這是舊的文章,但如果有人試圖做到這一點在節點webkit中,只需將.name更改爲.path,如下所示:changeEvent.target.files[0].path; 這對我很有用。

0

試試這個:

function readURL(input) { 
     if (input.files && input.files[0]) { 
      var reader = new FileReader(); 

      reader.onload = function (e) { 
       $('#tryy').attr('src', e.target.result); 
      } 

      reader.readAsDataURL(input.files[0]); 
     } 
    } 

    $("#tryyyy").change(function(){ 
     readURL(this); 
    }); 
+0

當你給出了一個答案,請加入一些信息,也可以什麼是OP的代碼中的實際問題。 – 2016-11-25 07:34:29

相關問題