You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2022/06/10 06:27:54 UTC

[GitHub] [cordova-plugin-file] lovelyelfpop opened a new issue, #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

lovelyelfpop opened a new issue, #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526

   # Bug Report
   
   ## Problem
   Android webview cannot display `<img>` with src="`https://localhost/__cdvfile_content__/...`"
   
   ### What is expected to happen?
   Android webview should display `<img>` with src="`https://localhost/__cdvfile_content__/...`"
   
   
   ### What does actually happen?
   ERR_CONNECTION_REFUSED in console,img not displaying
   
   
   ## Information
   `<img>` with src like `https://localhost/__cdvfile_asstes__/...` or `https://localhost/__cdvfile_files__/...` can display in webview, but not `https://localhost/__cdvfile_content__/...`, 
   
   
   ### Environment, Platform, Device
   Redmi K30 pro, Android 11
   
   
   
   ### Version information
   Cordova@11.0.0
   Cordova-Android@10.1.2
   cordova-plugin-file@7.0.0
   
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   
   
   ## Reason
   `WebViewAssetLoader.PathHandler` in `cordova-plugin-file\src\android\FileUtils.java` missing `content` uri handler.
   
   The right code is
   ```java
       public CordovaPluginPathHandler getPathHandler() {
           WebViewAssetLoader.PathHandler pathHandler = path -> {
               String targetFileSystem = null;
   
               if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("persistent"))) {
                   targetFileSystem = "persistent";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("temporary"))) {
                   targetFileSystem = "temporary";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("files"))) {
                   targetFileSystem = "files";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("documents"))) {
                   targetFileSystem = "documents";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("cache"))) {
                   targetFileSystem = "cache";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("root"))) {
                   targetFileSystem = "root";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("files-external"))) {
                   targetFileSystem = "files-external";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("sdcard"))) {
                   targetFileSystem = "sdcard";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("cache-external"))) {
                   targetFileSystem = "cache-external";
               } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("assets"))) {
                   targetFileSystem = "assets";
               }
               // --------------------added start--------------------
               else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("content"))) {
                   targetFileSystem = "content";
               }
               // --------------------added end--------------------
   
               boolean isAssetsFS = targetFileSystem == "assets";
   
               if (targetFileSystem != null) {
                   // Loop the registered file systems to find the target.
                   for (Filesystem fileSystem : filesystems) {
                       /*
                        * When target is discovered:
                        * 1. Transform the url path to the native path
                        * 2. Load the file contents
                        * 3. Get the file mime type
                        * 4. Return the file & mime information back we Web Resources
                        */
                       if (fileSystem.name.equals(targetFileSystem)) {
                           // E.g. replace __cdvfile_persistent__ with native path "/data/user/0/com.example.file/files/files/"
                           String fileSystemNativeUri = fileSystem.rootUri.toString().replace("file://", "");
                           String fileTarget = path.replace(LocalFilesystemURL.fsNameToCdvKeyword(targetFileSystem) + "/", fileSystemNativeUri);
                           File file = null;
   
                           if (isAssetsFS) {
                               fileTarget = fileTarget.replace("/android_asset/", "");
                           } else {
                               file = new File(fileTarget);
                           }
   
                           try {
                               // --------------------added start--------------------
                               if(targetFileSystem == "content") {
                                   ContentResolver cr = webView.getContext().getContentResolver();
                                   Uri uri = Uri.parse(fileTarget);
                                   InputStream fileIS = new FileInputStream(cr.openFileDescriptor(uri, "r").getFileDescriptor());
                                   String fileMimeType = cr.getType(uri);
   
                                   return new WebResourceResponse(fileMimeType, null, fileIS);
                               }
                               // --------------------added end--------------------
   
                               InputStream fileIS = !isAssetsFS ?
                                       new FileInputStream(file) :
                                       webView.getContext().getAssets().open(fileTarget);
   
                               String filePath = !isAssetsFS ? file.toString() : fileTarget;
                               Uri fileUri = Uri.parse(filePath);
                               String fileMimeType = getMimeType(fileUri);
   
                               return new WebResourceResponse(fileMimeType, null, fileIS);
                           } catch (FileNotFoundException e) {
                               Log.e(LOG_TAG, e.getMessage());
                           } catch (IOException e) {
                               Log.e(LOG_TAG, e.getMessage());
                           }
                       }
                   }
               }
   
               return null;
           };
   
           return new CordovaPluginPathHandler(pathHandler);
       }
   }
   ```
   


-- 
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: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] lovelyelfpop commented on issue #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

Posted by "lovelyelfpop (via GitHub)" <gi...@apache.org>.
lovelyelfpop commented on issue #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526#issuecomment-1635298365

   I've created a pull request
   https://github.com/apache/cordova-plugin-file/pull/582


-- 
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: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] HarelM commented on issue #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

Posted by GitBox <gi...@apache.org>.
HarelM commented on issue #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526#issuecomment-1357425511

   I think this issue is also resolved with #534 which solves #525. I'm not sure though. 
   All I know is that I'm currently using in production the branch in the PR in #534 and I would love it to be merged so I can use an official version and not a branch...
   Thanks!


-- 
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: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] HarelM commented on issue #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

Posted by GitBox <gi...@apache.org>.
HarelM commented on issue #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526#issuecomment-1203761854

   I've seen this too I believe in version 7.0.
   But the above change doesn't fix the call to `resolveLocalFilesystemUrl` which still I see in the debug that has `https://localhost/__cdvfile_content__/...` I think it has to do with the changes made in `ContentFilesystem.java`. I still need to test this theory though...
   


-- 
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: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] lovelyelfpop commented on issue #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

Posted by "lovelyelfpop (via GitHub)" <gi...@apache.org>.
lovelyelfpop commented on issue #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526#issuecomment-1436250745

   When will this gets fixed?


-- 
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: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek commented on issue #526: @7.0.0 Android webview cannot display img with src="https://localhost/__cdvfile_content__/..."

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #526:
URL: https://github.com/apache/cordova-plugin-file/issues/526#issuecomment-1357112259

   If content is all that is missing and
   
   ```
    else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("content"))) {
                   targetFileSystem = "content";
               }
   ```
   
   is what is needed to add it, then PR would definitely be welcome.


-- 
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: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org