regnete edited a comment on issue #1329:
URL: 
https://github.com/apache/cordova-android/issues/1329#issuecomment-924648282


   Facing similiar issue when using an absolute file url:
   ```javascript
   lFileUrl = 
'file:///data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg'
   xhr.open("GET", lFileUrl, true);
   xhr.onload = function() {
      console.log('loaded');
   }
   try {
       xhr.send();
   } catch (e) {
       console.error(e);
   }
   ```
   Error message on console:
   
   `Not allowed to load local resource: 
file:///data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg`
   
   Solution could be to provide something similar to 
`window.WkWebView.convertFilePath('your/file/path');` from `cordova-ios`.
   see 
https://github.com/apache/cordova-ios/blob/715c2dbfb273fb33721e8cf3f989ce7b20892d32/cordova-js-src/plugin/ios/wkwebkit.js#L28
   
   ```javascript
   
   async function resolveLocalFileSystemURL(uri){
           return new Promise(function (resolve, reject) {
               window.resolveLocalFileSystemURL(uri, resolve, (cause) => {
                   if (cause.code == FileError.NOT_FOUND_ERR)
                       resolve(null);
                   else reject({cause, uri, message: "cannot resolve local file 
system url"})
               });
           });
   }
   
   async function convertFilePath(uri){
      if(uri.startsWith('file://'){
         const resolved = await this.utils.resolveLocalFileSystemURL(uri);
          uri = resolved.toInternalURL().replace("cdvfile://localhost/", 
"https://"; + location.host + "/");
      }
      return uri;
   }
   
   lFileUrl = await 
convertFilePath('file:///data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg');
   xhr.open("GET", lFileUrl, true);
   xhr.onload = function() {
      console.log('loaded');
   }
   try {
       xhr.send();
   } catch (e) {
       console.error(e);
   }
   ```
   Error message in chrome debugger network panel: `net::ERR_CONNECTION_REFUSED`
   
   Looks like 
https://github.com/apache/cordova-android/blob/015db819aed3f35892d2b6035781ea4bd752149d/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
 is missing a 
https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.InternalStoragePathHandler
 to make `file:///data/user/0/com.company.stub/files` available at 
`https://localhost/files/....`. The solution should be able to provide access 
to all locations mentioned here: 
https://github.com/apache/cordova-plugin-file#android-file-system-layout


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