WICG / file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
https://wicg.github.io/file-system-access/
Other
654 stars 65 forks source link

Allow files with no extensions #406

Closed sbaechler closed 1 year ago

sbaechler commented 1 year ago

Currently, the spec disallows file without an extensions.

There are use-cases where the type of a file is known and the (legacy) software that exported it did not use extensions.

a-sully commented 1 year ago

Extensions are not required. See https://fs.spec.whatwg.org/#valid-file-name - although that definition is quite poor and likely to change soon, so follow along on https://github.com/whatwg/fs/issues/93 to see where this is probably heading

The text you linked is just for the file picker options. Meaning you can't specify "only give me files that don't have an extension"... which seems like a niche use case and not something I'd expect platform picker APIs (which generally filter by MIME type) to support anyways

Using excludeAcceptAllOption: false (which is the default) you should still be able to select files without an extension, and for the "save" file picker passing a suggestedName without an extension should work just fine (though please let us know if you find that not to be the case)

sbaechler commented 1 year ago

The use-case is the file-picker.

Currently it is only possible to allow files with file-endings or all files. But in our case a file has either a .xml ending or no ending. However, .png and .pdf should still not be allowed.

Here is an example of the configuration on mdn:

const pickerOpts = {
  types: [
    {
      description: "Images",
      accept: {
        "image/*": [".png", ".gif", ".jpeg", ".jpg"],
      },
    },
  ],
  excludeAcceptAllOption: true,
  multiple: false,
};

An option would be to support an empty string for a given mime-type. The system file picker could then allow files without file endings while still disable those with the wrong file ending.

const pickerOpts = {
  types: [
    {
      description: "SEPA Payment Files",
      accept: {
        "text/xml": [".xml", ".pain.001", ""],
      },
    },
  ],
  excludeAcceptAllOption: true,
  multiple: false,
};
a-sully commented 1 year ago

Meaning you can't specify "only give me files that don't have an extension"... which seems like a niche use case and not something I'd expect platform picker APIs (which generally filter by MIME type) to support anyways

I looked into this out of curiosity, but this does not seem to be something the underlying platforms support anyways. For example on Mac, NSOpenPanel takes an allowedContentTypes array, which takes a UTType that doesn't appear to be able to express "files with no type". Things look similarly not possible on Windows

I think excludeAcceptAllOption: true is your best bet, and you can always show another picker if the user selects a file of a type you don't support - which you'd need to do anyways, since extension-less files could be of any type. The user could just as easily select an extension-less file that's not a "SEPA Payment File" as they could select a PNG or anything else