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


   
   
   
   > we are facing a similar issue where existing cordova implementation to 
read a file from downloads folder is working but not in android 11. Have tried 
all possible changes suggested to use fileentry object to get reference and 
then copy to a location where application has access to but read itself is 
failing. Cordova version used is 9.x and cordova-file-plugin has been used to 
read file. Required feature is to allow user to select a file from device and 
upload it. Upload to server is in base64 format. Kindly advise
   > 
   > @alex-steinberg - can you please share your code snippet and clarify 
whether you are using cordova 9 or cordova 10?
   
   @alex-steinberg - We have set targetSdkVersion to 30 in config.xml file and 
created build using platform 9.1.0.
   
   Below code works fine in lower android version (till android 10). In android 
11 while reading a **pdf file** from download loaction, we get error as **GET 
file:///storage/emulated/0/Download/Test.pdf net::ERR_ACCESS_DENIED**
   
   this.fileChooser.open()
       .then(uri => {
         let fileName = null;
         let fileExtension = null;
         let fileType = null;
         let isvalid = true;
         this.filePath.resolveNativePath(uri)
             .then(filePath => {
               return this.base64EncodeFile(filePath);
             }).then((base64Data: any)=>{ 
                console.log(base64Data);
             })
         .catch(err => console.log(err));
       })
       .catch(e => console.log(e));
     }
     
     base64EncodeFile(src){
       return new Promise((resolve, reject) => {
         let xhr = new XMLHttpRequest();
         xhr.onload = function () {
           let reader = new FileReader();
           reader.onloadend = function () {
             let result = {
               base64: reader.result,
               size: xhr.response.size,
               type: xhr.response.type
             }
             resolve(result);
           }
           reader.readAsDataURL(xhr.response);
         };
         xhr.open('GET', src);
         xhr.responseType = 'blob';
         xhr.send();
       });
     }
   
   We have also tried below code 
    
   To copy from download folder to internal storage. It gives 
**{"code":1,"message":"NOT_FOUND_ERR"}** error
   
   pathsrc : file:///storage/emulated/0/Download/Test.pdf
   
   fileName : Test.pdf
   
    this.file.copyFile(pathsrc, fileName, this.file.dataDirectory, fileName).
               then((result) => { console.log('file copied :' + result);
               }).catch(err => console.log("copied err "+ 
JSON.stringify(err)));;
   
   Below code is using copyTo method, it gives error as **FileErrorĀ {code: 1}**
   
   window.resolveLocalFileSystemURL(pathsrc, function (fileSystem) {
               fileSystem.getFile(fileName, {
                 create: false, // try true first to make sure that there are 
no other problems around
                 exclusive: false
               }, function (fileEntry) {
                 
window.resolveLocalFileSystemURL(window.cordova.file.externalDataDirectory , 
function (newFileEntry) {      
                   fileEntry.copyTo(newFileEntry, fileName, function (result) {
                     console.log("save successfully:", result);
                   }, function (err) {
                     console.log("err-fileEntry.copyTo: ",err);
                   });
                 }, function (err) {
                   console.log("err-window.resolveLocalFileSystemURL: ",err);
                 });
               }, function (err) {
                 console.log("err-fileSystem.getFile: ",err);
               });
             }, function (err) {
               console.log("err-resolveLocalFileSystemURL: ",err);
             });
   


-- 
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.

To unsubscribe, e-mail: [email protected]

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