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

Missing file extension in download save dialog #10121

Closed
steverandy opened this issue Jul 26, 2017 · 22 comments
Closed

Missing file extension in download save dialog #10121

steverandy opened this issue Jul 26, 2017 · 22 comments

Comments

@steverandy
Copy link

  • Electron version: 1.7.5
  • Operating system: macOS 10.12.6

Expected behavior

Save dialog should show filename with the correct extension.

Actual behavior

Extension is missing in the filename on the save dialog window.

screen shot 2017-07-26 at 10 51 42 pm

How to reproduce

Download a file from a webview.

@zeke
Copy link
Contributor

zeke commented Jul 26, 2017

@steverandy do you have Finder configured to show extensions?

screen shot 2017-07-26 at 2 26 26 pm

@deltaroe
Copy link

We've run into this as well on 1.7.4 and macOS 10.12

With "Show all filename extensions" enabled the extension is added when a file is downloaded, when it's off downloaded files are stripped of their extensions and saved as a bare filename.

Reverting to 1.6.11 resolves the issue for us

@steverandy
Copy link
Author

@zeke I don't have the finder config enabled.

When it is enabled, it fixes the issue.
Is this behavior somewhat controlled by the Finder?

@steverandy
Copy link
Author

I can confirm that the issue is present since v1.7.4.

@javan
Copy link
Contributor

javan commented Jul 31, 2017

Confirmed here on macOS 10.12.6 + Electron 1.7.5 too. Curiously, it only happens in a packaged (with electron-packager in my case) .app. The file extension is present when launching the app locally with electron ..

@kevinsawicki
Copy link
Contributor

This looks like a possible regression from #9610, @shubham2892 would you be able to take a look?

@juanmnl
Copy link

juanmnl commented Aug 23, 2017

Same here, macOS Sierra 10.12.6, electron v1.7.5

Finder's "show all filename extensions" fixes it, but I don't expect users to have it enabled by default.

@bennycode
Copy link
Contributor

Encountered the same issue with Electron 1.7.6. When Finder's "Show all filename extensions" is enabled, then files are saved as "file.txt". When the setting is disabled, files will get saved as "file" (without extension).

This behaviour has been different in the past (with Electron 1.6). At that time files were always saved with their extension.

@bennycode
Copy link
Contributor

I tried to cheat the save dialog the following way:

  1. Downloading file as Blob using XMLHttpRequest (with responseType of arraybuffer)
  2. Creating URL from the Blob (using URL.createObjectURL)
  3. Creating anchor tag with href property set to Blob URL
  4. Setting download property of anchor tag to fake filename
  5. Triggering click on anchor tag

Unfortunately it still doesn't work. You can test it in your own Electron app using the following snippet from the DevConsole within Electron:

const url = window.URL.createObjectURL(new Blob());
const anchor = document.createElement('a');
document.body.appendChild(anchor);
anchor.href = url;
anchor.download = 'file.txt';
anchor.style = 'display: none';
anchor.click();

Although anchor is set to the fixed value file.txt, it depends on the macOS Finder setting if the extension is shown in the save dialog or not.

@dengyaolong
Copy link
Contributor

really harmful change~Many user feedback file download but can't open cause extend name is lost. Any hack?

@javan
Copy link
Contributor

javan commented Sep 2, 2017

We've had customers report this issue on Windows 10 as well. There's a similar OS setting: http://www.thewindowsclub.com/show-file-extensions-in-windows

@MarshallOfSound
Copy link
Member

I just spent a fair time trying to debug this, it looks like our dialog logic is correct (still) but is not being triggered by our download manager delegates. Will investigate more when I get a chance, at the moment my thoughts are somewhere in a Chromium update our code stopped being executed

@dengyaolong
Copy link
Contributor

Now, I prompt the saveDialog and get the filename, add extend name(get by request) when no extend name set by use. Really strange, but work...

@marcoconti83
Copy link

Hey @dengyaolong,
thanks for the suggestion on how to "hack" a solution. Could you please explain more how you do it? Any code you can share with us?

@javan
Copy link
Contributor

javan commented Sep 4, 2017

This looks like a possible regression from #9610

@MarshallOfSound, have you looked into that change as a possible cause?

@dengyaolong
Copy link
Contributor

@marcoconti83 I upload my sample code to https://github.com/dengyaolong/electron-downloader/blob/master/index.js

@marcoconti83
Copy link

@dengyaolong thanks!

@bennycode
Copy link
Contributor

@dengyaolong With your 'will-download' listener I am able to get the filename (plus it's extension). 🎉

However, the 'will-download' event only triggers for after the "Save as" dialog has been shown. Is it the same for you? Because I want to fill in the filename (including extension) beforehand.

@dengyaolong
Copy link
Contributor

@bennyn I update the listener, now , you can set 'opts.dir' to set saveDir without dialog.
ps. just call item.setSavePath like my code. https://github.com/dengyaolong/electron-downloader/blob/master/index.js

@poiru
Copy link
Contributor

poiru commented Sep 8, 2017

Fixed by #10469.

@BONDbATIF
Copy link

@steverandy @javan
I am using electron v1.8.4 in mac .Still extension issue is not fixed in mac .
Any update ?

@Sharcoux
Copy link

Sharcoux commented Jun 3, 2022

I'm stiill having the issue in Windows as of "electron-builder": "22.10.5", and "electron": "^18.1.0",

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

No branches or pull requests