GetFileForSaving - persist file format?

When using the file picker to save a file:

myFile = await storage.localFileSystem.getFileForSaving(fileName + .png);

If a user removes the ‘.png’ from the file name, we end up with a unknown file type when it is saved to the disk using:


Inspecting shows the name without the file extension.

Any ideas on persisting this? File is read only, so I can’t edit .name.


Have you tried passing the file extension as allowed file type option (as is documented here)? I haven’t tried this out myself but am wondering if that might force the extension. Like so:

myFile = await storage.localFileSystem.getFileForSaving(fileName + .png, { types: [ "png" ]});

Thanks for the suggestion. I’ve tried this and no luck. All this seems to do is filter what the type drop down permits. I’m able to remove the extension from the name.

I create a file from this getFileForSaving. When I later download this fileArray:

const fileArray = await fileDownload.arrayBuffer();
await exportDownloadFile.write(fileArray);

The exportdownloadFile is written to with the correct file contents. However, the file is without extension so it is an unknown file type on the storage system.

@kerrishotts @Jarda Any ideas?

I resolved this in the end. Rather than work around permission issues (which I’m sure is the problem here as my fileforsaving name is a readonly) I simply check if the fileExtension has been removed. If it has, I use createEntryWithUrl, overwriting the file and putting the extension back on. This is an empty file and not written to disk until there is content. The content is written later when I use my file download.