apache / cordova-plugin-file

Apache Cordova File Plugin
https://cordova.apache.org/
Apache License 2.0
740 stars 757 forks source link

How can I parse a mideastore path to cdvfile protocol ? #602

Closed DUWENINK closed 8 months ago

DUWENINK commented 8 months ago

Bug Report

Problem

What is expected to happen?

I use my plugin to record the screen can I save it to gallery , and I want to display it on device at the same time,my device load a remote url like 'https://192.168.1.113:7702/MobileServer/dist/index.html',I use this code

this.convertToCdvfile = function (path) {
    var get = new Promise((resolve, reject) => {
        try {
            window.resolveLocalFileSystemURL(path, function (fileEntry) {
                var cdvfilePath = fileEntry.toURL();
                console.log("convertToCdvfile:" + JSON.stringify(fileEntry));
                resolve(cdvfilePath);
            }, function (error) {
                reject('ERROR: ' + JSON.stringify(error));
            });
        }
        catch (ex) {
            reject('ERROR: ' +  JSON.stringify(ex));
        }
    });
    return get;
};

and then I get

convertToCdvfile:{"isFile":true,"isDirectory":false,"name":"366","fullPath":"/media/external/video/media/366","filesystem":"<FileSystem: content>","nativeURL":"content://media/external/video/media/366"}
cordova-funcs.js:991
convertToCdvfile:content://media/external/video/media/366->https://192.168.1.113:7702/__cdvfile_content__/media/external/video/media/366

the filepath I can not set to the src to the video

and also i get list of paths just like 'https://192.168.1.113:7702/__cdvfile_content__/media/external/video/media/366' 'content://media/external/video/media/357' 'file:///storage/emulated/0/Movies/PR-DC/DWK_6b62dfc0-83c8-4294-9065-d1080bab8a1d.mp4' file:///storage/emulated/com.duwenink.app/Movies/PR-DC/DWK_5b029226-68e9-4441-9082-8499a488cc70.mp4 https://192.168.1.113:7702/__cdvfile_content__/media/external/video/media/357 https://192.168.1.113:7702/__cdvfile_sdcard__/Movies/PR-DC/DWK_6b62dfc0-83c8-4294-9065-d1080bab8a1d.mp4

i try many ways but why i can not the the cdvfile easily????????????????????????????????????

breautek commented 8 months ago

If you're expecting a cdvfile:// path, that's not really supported anymore due to CORs. I believe cdvfile:// is still used on file-based hosted app content, but on scheme/http (WebViewAssetLoader) hosted app content, it retains the origin and have the app route to the local path.

Normally the path https://<app-host>/__cdvfile_sdcard__/Movies/PR-DC/DWK_6b62dfc0-83c8-4294-9065-d1080bab8a1d.mp4 is handled by the WebViewAssetLoader, which parses the __cdvfile_sdcard_ part to know where to redirect the rest of the path to the local filesystem.

However you're using a remote web resource as your app, so you're not using the WebViewAssetLoader, which isn't really a supported configuration. Additionally, your remote web server won't have access to local device files to actually serve that content. The app needs to be hosted through the locally through the WebViewAssetLoader (which means your app web assets like your index.html and JS, etc needs to be on the local device, not served remotely) for the cdv file work.

But if you're using external storage mediums (e.g. /storage/emulated/0/, there are a several other issues with using a file-based API due to Android's scoped storage mechanism). So, I'd also consider using a media-store plugin, although I'm not sure if it will solve all of your issues given your current environment.

Closing as won't fix.