Cordova - Speichern Sie Bild aus url in das Gerät ein photo-Galerie
Ich entwickle eine Anwendung mit Apache Cordova lädt und speichert Bilder, aber ich kann nicht speichern und das anzeigen der Galerie, das Bild geht file:///data/data
während ich versuche, die laufen auf Android, was kann ich tun?
Mein code:
function download(URL, Folder_Name, File_Name) {
//step to request a file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail);
function fileSystemSuccess(fileSystem) {
var download_link = encodeURI(URL);
var ext = download_link.substring(download_link.lastIndexOf('.') + 1); //Get extension of URL
var directoryEntry = fileSystem.root; //to get root path of directory
directoryEntry.getDirectory(Folder_Name, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); //creating folder in sdcard
var rootdir = fileSystem.root;
var fp = rootdir.toURL(); //Returns Fulpath of local directory
console.log(rootdir);
fp = fp + "/" + Folder_Name + "/" + File_Name; //fullpath and name of the file which we want to give
//download function call
filetransfer(download_link, fp);
}
function onDirectorySuccess(parent) {
//alert("Sucesso");
}
function onDirectoryFail(error) {
//Error while creating directory
alert("Unable to create new directory: " + error.code);
}
function fileSystemFail(evt) {
//Unable to access file system
alert(evt.target.error.code);
}
}
function filetransfer(download_link, fp) {
var fileTransfer = new FileTransfer();
console.log(fp);
//File download function with URL and local path
fileTransfer.download(download_link, fp,
function (entry) {
//alert("download complete: " + entry.fullPath);
},
function (error) {
//Download abort errors or download failed errors
console.log(error);
alert(error.exception);
alert("download error source " + error.source);
//alert("download error target " + error.target);
//alert("upload error code" + error.code);
}
);
}
- Möglich, Duplikat der Phonegap - Speichern Sie Bild aus url in das Gerät ein photo-Galerie
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wurden die Bilder gespeichert, allerdings benötigt die Media Scanner index der Bilder auf gallery
Media Scanner:
Wie war die Arbeit mit Apache Cordova /PhoneGap, die es bietet keine native Methode zum aktualisieren der Bilder in der nativen Galerie, ich musste nur auf der Suche nach einem plugin, um diese Arbeit zu tun. Die plugins, die ich gefunden wurden:
cordova-mediascanner-plugins
MediaScannerPlugin
Beide haben eine grundlegende Dokumentation, aber ich verwendet, cordova-mediascanner-plugins.
Durch die Umsetzung dieses plugin, nur meine modifizierten
filetransfer
Methodebitte versuchen Sie, importieren Sie das plugin in Ihrem Projekt :-
https://github.com/devgeeks/Canvas2ImagePlugin.git