Skip to content

Should sharing zero size files be allowed? #229

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

Closed
tomayac opened this issue Dec 21, 2021 · 10 comments
Closed

Should sharing zero size files be allowed? #229

tomayac opened this issue Dec 21, 2021 · 10 comments
Labels

Comments

@tomayac
Copy link
Contributor

tomayac commented Dec 21, 2021

Should sharing of an opaque response be allowed?

try {
  const url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
  const blob = await fetch(url, {mode: 'no-cors'}).then(response => response.blob());
  const file = new File([blob], 'image.png');
  const data = {
    files: [file]
  };
  if (!navigator.canShare(data)) {
    throw new Error('Cannot share');
  }
  await navigator.share(data);
} catch (err) {
  console.error(err.name, err.message);
}

For this example, navigator.canShare() returns true, but the actual share operation then fails. Play with this example deployed.

Possibly related: #173

@annevk
Copy link
Member

annevk commented May 25, 2022

Why would response.blob() not throw here?

@saschanaz
Copy link
Member

Gecko does not throw on .blob() here either, btw.

@annevk
Copy link
Member

annevk commented May 25, 2022

Yeah, I realized after posting that it likely won't fail, but the blob will be empty so you won't end up sharing anything.

@marcoscaceres
Copy link
Member

marcoscaceres commented May 30, 2022

Is just checking if the file is zero size sufficient? If yes, we could just add that check for each file (and return false).

@marcoscaceres marcoscaceres changed the title Sharing opaque responses Should sharing zero size files be allowed? May 30, 2022
@marcoscaceres
Copy link
Member

Alternative: filter out all zero length files. If results in empty list of files, return false.

@marcoscaceres
Copy link
Member

@tomayac, what do you think? Drop the empty files on the floor (and do nothing if they are all empty)? It seems like the most user friendly solution.

@saschanaz
Copy link
Member

An empty file still has some info (the filename) so I wonder implicitly filtering it out may add some confusion.

@marcoscaceres
Copy link
Member

marcoscaceres commented May 31, 2022

Well, it depends. On MacOS's various handlers it's kinda confusing, because some apps just spin up with nothing to share (e.g., in Notes.app). The name doesn't seem to play a significant role.

Others show an empty preview of a file. In Messages.app, for example:

When normally you would see a preview:

What happens on Windows?

@saschanaz
Copy link
Member

Looks like this when an "Share to" item is selected:

image

@marcoscaceres
Copy link
Member

Ok, let's got with doing nothing here. Developer should decide and, if they so choose, filter out empty files for situations like @tomayac found. However, for certain applications (e.g., text), it could make perfect sense to share an empty text file with just a file name.

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

Successfully merging a pull request may close this issue.

4 participants