2016-03-23 20 views
0

我有一個具有圖像的網址。我想用chrome api下載那個圖片。我正在開發一個Chrome應用程序,而不是擴展。 任何人都可以請告訴我我要去哪裏錯?如何使用chrome文件系統api從chrome應用中的url下載圖片?

我的代碼:

service('fileService', function($window){ 
    this.saveUserInfo = function(theFilePath) { 
     // filepath is the url passed from controller{ 
     // Get the directory entry stored (if any). 
     var fileUrl = ""; 
     var config = { 
      type: 'saveFile', 
      suggestedName: 'TheBee.png', 
      accepts:[{extensions: ['png', 'jpg', 'jpeg']}] 
     }; 

     chrome.fileSystem.chooseEntry(config, function(writableEntry) { 

      chrome.fileSystem.getWritableEntry(writableEntry, function(entry1) { 

       entry1.getFile(theFilePath, {create:true}, function(entry2) { 

        entry2.createWriter(function(writer) { 
         var blob = new Blob({type: 'image/png'}); 
         writer.write(blob); 
        }); 

       }); 

      }); 

     }); 

    }); 

}); 
+0

blob構造函數不應該帶2個參數嗎? '新的Blob([數據],{opts})' – Endless

回答

0

變化

var blob = new Blob({type: 'image/png'}); 

var blob = new Blob([entry1],{type: 'image/png'}); 

團塊構造器acceptes斑點部分:MSDN =>斑點(blobParts [,選項])

0

你不能使用getFile ry1因爲它本身就是一個文件。您需要將config.type更改爲「openDirectory」

您還需要添加一個空數組作爲blob構造函數的第一個輸入。

+0

你能提供一個笨蛋或什麼?我對鉻api非常陌生。如果您可以提供具有相同功能的plunker,這將非常有幫助。 – guppie

相關問題