tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Can not download in front end

Open zhaoygcq opened this issue 1 year ago • 15 comments

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

zhaoygcq avatar Jul 09 '22 15:07 zhaoygcq

upstream: https://github.com/tauri-apps/wry/issues/349

amrbashir avatar Jul 09 '22 21:07 amrbashir

it seems there is no answer; @amrbashir

zhaoygcq avatar Jul 10 '22 00:07 zhaoygcq

it seems there is no answer;

It's a tracking issue = it's not implemented yet.

FabianLars avatar Jul 10 '22 09:07 FabianLars

it seems there is no answer;

It's a tracking issue = it's not implemented yet.

i see, thanks

zhaoygcq avatar Jul 10 '22 11:07 zhaoygcq

It looks like this has been solved upstream. Has that made it into any releases for tauri? Are there any workarounds?

candrewlee14 avatar Jan 25 '23 06:01 candrewlee14

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?

matthme avatar Jan 30 '23 16:01 matthme

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.

FabianLars avatar Jan 30 '23 16:01 FabianLars

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.)

reupen avatar Jun 08 '23 10:06 reupen

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 ~/

ManuelRauber avatar Jun 25 '23 08:06 ManuelRauber

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.

matthme avatar Sep 20 '23 10:09 matthme

Also critical for us if there is a chance of bringing this closer on the roadmap

rosseyre avatar Oct 26 '23 12:10 rosseyre

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.

kirill-konshin avatar Dec 21 '23 17:12 kirill-konshin

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?

Amerlander avatar Feb 19 '24 11:02 Amerlander

@FabianLars Would be useful to know if this issue is likely to be fixed in the 2.0 release.

ImageDeeply avatar Apr 21 '24 18:04 ImageDeeply

i don't know either, probably not in 2.0.0 because of the audit 🤔

FabianLars avatar Apr 21 '24 18:04 FabianLars