ฉันมีแอป Phonegap ซึ่งฉันพยายามบันทึกไฟล์ลงในที่จัดเก็บข้อมูลของอุปกรณ์ แต่หลังจากที่ฉันได้รวมปลั๊กอิน cordova-plugin-file
ไว้ในไฟล์ config.xml แล้ว ออบเจ็กต์ cordova.file
ก็ยังไม่ได้กำหนดไว้ ฉันกำลังสร้างแอปโดยใช้ Phonegap Build โดยใช้ cli cli-6.5.0
การใช้เครื่องมือตรวจสอบ Chrome ฉันเห็นว่าเมื่อฉันพยายามบันทึกวัตถุ cordova.file
มันจะส่งคืนไม่ได้กำหนด การบันทึก cordova
จะส่งคืนวัตถุ Cordova ในบันทึก
นี่คือบันทึกจากคอนโซลตามที่อธิบายไว้ข้างต้น:
บรรทัดต่อไปนี้อยู่ในไฟล์ config.xml ของฉัน:
<plugin name="cordova-plugin-file" source="npm" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
นี่คือรหัสที่ฉันใช้ในการบันทึกไฟล์:
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(dir) {
console.log("Creating file");
var fileName;
do {
fileName = prompt("Please enter a name for your file", "");
} while(fileName == null || fileName == "");
dir.getFile(fileName, {create:true}, function(file) {
console.log("File created succesfully");
file.createWriter(function(fileWriter) {
console.log("Writing content to file");
fileWriter.write(imageBlob);
}, function(){
console.log('Unable to save file');
});
});
});
อย่างไรก็ตาม ฟังก์ชันนี้ไม่เคยทำงานและฉันไม่เห็นบันทึกใดๆ ในคอนโซลผ่านเครื่องมือตรวจสอบ Chrome imageBlob
เป็นวัตถุ Blob ที่มีอิมเมจ base64 ที่ถูกแปลงเป็นวัตถุ Blob แต่โค้ดไม่เคยไปไกลขนาดนั้น
ฉันได้ลองใช้ปลั๊กอินเวอร์ชันเก่าโดยใช้แอตทริบิวต์ spec
ในไฟล์ config.xml แล้ว แต่ก็ไม่ได้ผล