I am trying to use Cordova plugin to download files in an external folder. Here is my code
const writeFile = (path, filename, blob)=> {
return new Promise((resolve, reject) => {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (dirpar) {
dirpar.getDirectory(path, { create: true }, function (dir) {
dir.getFile(filename, { create: true, exclusive: false }, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = () =>{
console.log("Successful file write...");
console.log("=========================");
console.log("=========================");
console.log("=========================");
console.log("=========================");
console.log("=========================");
console.log(JSON.stringify(fileEntry));
console.log(fileEntry.fullPath);
return resolve
}
fileWriter.onerror = reject
fileWriter.write(blob);
});
}, reject);
}, reject);
}, reject);
});
}
The error I am getting in the android studio is as follows.
ypersign.cordova D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10153; state: DISABLED
2021-02-26 17:01:33.775 10648-10715/com.hypersign.cordova W/AssetFilesystem: Asset manifest not found. Recursive copies and directory listing will be slow.
2021-02-26 17:01:33.812 296-358/? D/goldfish-address-space: allocate: Ask for block of size 0x888f0
2021-02-26 17:01:33.813 296-358/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3f8991000 size 0x8a000
2021-02-26 17:01:33.820 296-358/? D/goldfish-address-space: allocate: Ask for block of size 0x888f0
2021-02-26 17:01:33.820 296-358/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3ee8b4000 size 0x8a000
2021-02-26 17:01:33.822 296-358/? D/goldfish-address-space: allocate: Ask for block of size 0x888f0
2021-02-26 17:01:33.822 296-358/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3ee82a000 size 0x8a000
2021-02-26 17:01:33.923 529-2448/system_process D/CompatibilityChangeReporter: Compat change id reported: 149924527; UID 10153; state: ENABLED
2021-02-26 17:01:33.924 529-2448/system_process D/CompatibilityChangeReporter: Compat change id reported: 132649864; UID 10153; state: DISABLED
2021-02-26 17:01:33.932 1550-1997/com.google.android.providers.media.module W/MediaProvider: Forgot to handle a top level directory in getContentUriForFile?
2021-02-26 17:01:33.940 1550-1997/com.google.android.providers.media.module E/MediaProvider: insertFileIfNecessary failed
java.lang.IllegalArgumentException: Primary directory download not allowed for content://media/external_primary/file; allowed directories are [Download, Documents]
at com.android.providers.media.MediaProvider.ensureFileColumns(MediaProvider.java:2682)
at com.android.providers.media.MediaProvider.ensureUniqueFileColumns(MediaProvider.java:2347)
at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:2957)
at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3486)
at com.android.providers.media.MediaProvider.insert(MediaProvider.java:3208)
at com.android.providers.media.MediaProvider.insertFileForFuse(MediaProvider.java:6655)
at com.android.providers.media.MediaProvider.insertFileIfNecessaryForFuse(MediaProvider.java:6742)
2021-02-26 17:01:33.948 10648-10648/com.hypersign.cordova I/chromium: [INFO:CONSOLE(113)] "Uncaught (in promise) #<FileError>", source: file:///android_asset/www/plugins/cordova-plugin-file/www/DirectoryEntry.js (113)
2021-02-26 17:01:34.302 1408-1463/com.google.android.inputmethod.latin I/PeriodicStatsRunner: PeriodicStatsRunner.call():180 call()
2021-02-26 17:01:34.303 1408-1463/com.google.android.inputmethod.latin I/PeriodicStatsRunner: PeriodicStatsRunner.call():184 No submit PeriodicStats since input started.
2021-02-26 17:01:35.807 529-641/system_process W/NotificationService: Toast already killed. pkg=com.hypersign.cordova [email protected]
2021-02-26 17:01:35.813 529-641/system_process I/NotificationService: cancelToast pkg=com.hypersign.cordova [email protected]
2021-02-26 17:01:35.813 529-641/system_process W/NotificationService: Toast already cancelled. pkg=com.hypersign.cordova [email protected]
2021-02-26 17:01:37.285 529-569/system_process W/WindowManager: Unable to start animation, surface is null or no children.
You can observe following issues
Uncaught (in promise) #<FileError>
Any help regarding this would be great
Thanks
Source: Android Questions