2016-03-23 4 views
0

Ich habe eine URL, die ein Bild hat. Ich möchte dieses Bild mit Chrome API herunterladen. Ich entwickle eine Chrome App und keine Erweiterung. Kann mir bitte jemand sagen, wo ich falsch liege ??Wie Bild von einer URL in Chrome App mit Chrome-Dateisystem API herunterladen?

Mein Code:

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

Sollte der Blob-Konstruktor nicht zwei Argumente haben? 'neuer Blob ([data], {opts})' – Endless

Antwort

0

ändern

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

Um

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

The Blob contructor acceptes Teile Blob: MSDN => Blob (blobParts [Optionen])

0

Sie können getFile nicht auf ent verwenden Ry1, weil es eine Datei selbst ist. Sie müssen config.type in "openDirectory" ändern.

Sie müssen auch ein leeres Array als erste Eingabe zum Blob-Konstruktor hinzufügen.

+0

Kannst du bitte einen Plünderer oder sowas zur Verfügung stellen? Ich bin sehr neu in der Chrom-API. Es wäre wirklich hilfreich, wenn Sie mit Plunker mit gleicher Funktionalität versorgen können. – guppie

Verwandte Themen