Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MichaelMaenner opened this issue May 3, 2023 · 2 comments
Open

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

MichaelMaenner opened this issue May 3, 2023 · 2 comments

Comments

@MichaelMaenner
Copy link

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
Copy link
Owner

carsten-klaffke commented May 9, 2023

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants