victorvhpg commented on issue #426:
URL: 
https://github.com/apache/cordova-plugin-file/issues/426#issuecomment-825080261


   > I am using ionic 4 and I faced the same issue so I tried the ionic 4 
version of resolveDirectoryUrl(cordova.file.externalRootDirectory, function 
(dirEntry) {)) and on success function I used dirEntry.getDirectory 
('Download'... and I can create folders and save files to the Download folders 
on android 11 without adding android:requestLegacyExternalStorage="true". Here 
is the code for ionic 4. I have also tried to convert it to the normal web 
version.
   > 
   > ```
   > createDirectory(rootDir) {
   >     return new Promise((res, rej) => {
   >       this.file.resolveDirectoryUrl(rootDir).then((rootDirEntry)=>{
   >         
   >         rootDirEntry.getDirectory('Download', { create: false, 
exclusive:false},  (dirEntry) =>{
   >           dirEntry.getDirectory('updates', { create: true, 
exclusive:false}, (subDirEntry) =>{
   >             this.updateDir = subDirEntry;
   >             this.appDir = dirEntry;
   >             res(this.updateDir)
   >           }, (err)=> {
   >             this.onErrorGetDir(rootDir+'Download/','updates');
   >             rej(err)
   >           })
   >         }, (err)=> {
   >           this.onErrorGetDir(rootDir,'Download')
   >           rej(err)
   >         })
   >       })
   >       
   >     })
   >   }
   > ```
   > 
   > and the normal web version. Note that I have only tested the ionic 4 
version of this code.
   > 
   > ```
   > function createDirectory(rootDir /*cordova.file.externalRootDirectory*/) {
   >     window.resolveDirectoryURL(rootDir, function (rootDirEntry) {
   >       dirEntry.getDirectory('Download', { create: false, exclusive:false}, 
function (dirEntry) {
   >         dirEntry.getDirectory('updates', { create: true, exclusive:false}, 
function (subDirEntry) {
   >             /* delete a file or donwload a file using 
cordova-plugin-advanced-http.
   >                 I tested mine using cordova-plugin-advanced-http to 
download a file to this folder */
   >             createFile(subDirEntry, "fileInNewSubDir.txt");
   > 
   >         }, onErrorGetDir);
   >       }, onErrorGetDir);
   >     })
   >   }
   > ```
   > 
   > This doesn't allow you to write or read from the root directory but works 
with the download directory and probably other sub directories in the root 
directory.
   > You will need READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.
   
   i can't delete/update a file inside 'Download' folder  without flag 
'requestLegacyExternalStorage'  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to