carsten-klaffke / send-intent

Repository for send-intent Capacitor plugin
MIT License
106 stars 12 forks source link

ShareViewController transfers too many '/' in file url #79

Open MichaelMaenner opened 1 year ago

MichaelMaenner commented 1 year ago

Describe the bug If i share a file, e.g. an image, the function createSharedFileUrl of the ShareViewController passes to many /

file%3A%2F%2F%2Fprivate%2Fvar%2Fmobile%2FContainers%2FShared%2FAppGroup%2F1C0BA5F1-DE70-123D-8435-1F125779A3CE%2F%2FIMG_0029.PNG
file:///private/var/mobile/Containers/Shared/AppGroup/1C0BA5F1-DE70-123D-8435-1F125779A3CE//IMG_0029.PNG

So, i get file:/// and //filename.PNG

I can remove the + "/" + from inside the createSharedFileUrl which helps with the // in front of the filename, but i cant figure out how to remove one of the /// without manipulating the file url itself.

To Reproduce Steps to reproduce the behavior:

  1. Create an Capacitor App with the given send-intent example
  2. Share a File with the App
  3. App cant handle File because of too many /

Expected behavior The shared file url should look like that:

file%3A%2F%2Fprivate%2Fvar%2Fmobile%2FContainers%2FShared%2FAppGroup%2F1C0BA5F1-DE70-123D-8435-1F125779A3CE%2FIMG_0029.PNG
file://private/var/mobile/Containers/Shared/AppGroup/1C0BA5F1-DE70-123D-8435-1F125779A3CE/IMG_0029.PNG

Additional context Currently working with "send-intent": "^3.0.12"

Inside of my Capacitor/Angular App i have added some sort of Workaround for that. Its definitely not pretty, but it works. But i also want to get rid of it.

      try {
        intent.url = intent.url.replaceAll('%2F%2F', '%2F'); // '//' -> '/'
        if (!intent.url.includes('%3A%2F%2F') && intent.url.includes('%3A%2F')) {
          intent.url = intent.url.replace('%3A%2F', '%3A%2F%2F'); // ':/' -> '://';
        }
        const resultUrl = decodeURIComponent(intent.url);
        ...
carsten-klaffke commented 1 year ago

Hello Michael! The triple slash comes from the OS and I think it is correct. Please have a look at this thread: https://superuser.com/questions/352133/why-do-file-urls-start-with-3-slashes Looks like this is following the URL specification (didn't know that either). I wonder why your app can't handle this. For me the following code works (with @capacitor/filesystem): var content = await Filesystem.readFile({ path: decodeURIComponent(result.url) }); I will remove the extra slash in front of the filename - thanks for the hint! Best regards

MichaelMaenner commented 1 year ago

Again what learned with the triple slash - it joust doesn't look correct đŸ˜„

Tbh i have no idea why my app wasn't able to process the URL with the /// in the first place. I reworked the complete file handling on our part of the app and now it works as expected with the decodeUriComponent()

Greets & thanks, Michael