tauri
tauri copied to clipboard
[bug] Can not download in front end
Describe the bug
in the browser, we can use like this:
const eleLink = document.createElement("a");
eleLink.href = url;
eleLink.download = `${title} - ${artist}`;
eleLink.style.display = "none";
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
to download file in front; but in tauri,this function can not take effect.
Reproduction
No response
Expected behavior
No response
Platform and versions
› OS: Mac OS 12.4.0 X64
› Node.js: 16.14.0
› npm: 8.3.1
› pnpm: 6.32.3
› yarn: 1.22.17
› rustup: 1.24.3
› rustc: 1.61.0
› cargo: 1.61.0
› Rust toolchain: stable-aarch64-apple-darwin
Stack trace
No response
Additional context
No response
upstream: https://github.com/tauri-apps/wry/issues/349
it seems there is no answer; @amrbashir
it seems there is no answer;
It's a tracking issue = it's not implemented yet.
it seems there is no answer;
It's a tracking issue = it's not implemented yet.
i see, thanks
It looks like this has been solved upstream. Has that made it into any releases for tauri? Are there any workarounds?
Yes, still not working on macOS with tauri 1.2.4. It does work on Linux though at least since tauri 1.2.3. So has it maybe only been partially fixed by https://github.com/tauri-apps/wry/pull/530?
it still needs to be implemented in Tauri. wry#530 just made it possible to do so (by adding new apis). 530 by itself shouldn't have added any behavior changes outside these new apis.
My experience of the out of the box behaviour of downloads (Tauri 1.3.0):
- On Windows, files are downloaded to the downloads folder. The web view shows a notification. If the file already exists, the new file is saved with a unique name.
- On Linux (Ubuntu 22.04), files are downloaded to the downloads folder. There is no notification from the web view. If the file already exists, it's deleted and no new file is saved.
(I don't have access to macOS to test there.)
My experience of the out of the box behaviour of downloads (Tauri 1.3.0):
- On Windows, files are downloaded to the downloads folder. The web view shows a notification. If the file already exists, the new file is saved with a unique name.
- On Linux (Ubuntu 22.04), files are downloaded to the downloads folder. There is no notification from the web view. If the file already exists, it's deleted and no new file is saved.
(I don't have access to macOS to test there.)
On macOS nothing seems to happen at all. No errors in the console, no file is downloaded.
At least not to this locations:
- Desktop
- Documents
- User Folder
~/
Is there any plan for this being added to tauri still? It's still not working in tauri 1.4 almost one year after it being fixed upstream (it was planned apparently to be added to tauri 1.3). It's quite a critical issue for us.
Also critical for us if there is a chance of bringing this closer on the roadmap
Temporary solution:
import { saveAs } from 'file-saver';
import { save } from '@tauri-apps/api/dialog';
import { writeTextFile } from '@tauri-apps/api/fs';
export const downloadFile = async (filename, text, type = 'application/json') => {
if (window.__TAURI__) {
const filePath = await save({ defaultPath: filename });
await writeTextFile(filePath, text);
} else {
saveAs(new Blob([text], { type }), filename);
}
};
Don't forget to enable dialogs.
I use Tauri as a wrapper to serve static builds. I guess the temporary solution only works if I would change all links to use the downloadFile
-function instead of just being links?
@FabianLars Would be useful to know if this issue is likely to be fixed in the 2.0 release.
i don't know either, probably not in 2.0.0 because of the audit 🤔