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

Add download link support #349

Closed
bdjnk opened this issue Jul 16, 2021 · 7 comments
Closed

Add download link support #349

bdjnk opened this issue Jul 16, 2021 · 7 comments
Labels
help wanted Help is requested to fix this issue platform: All type: feature request

Comments

@bdjnk
Copy link

bdjnk commented Jul 16, 2021

Describe the bug

Generate an a tag with the download attribute set and the href attribute pointing to a blob: URL. For example the following.

<a download="hello.txt" href='#' id="link">Download</a>
<script>
const blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>

(example source)

Clicking such a link in any modern browser will initiate download of the linked resource. In Tauri, nothing happens.

To Reproduce

  1. Generate an a tag with the download attribute set and the href attribute pointing to a blob: URL.
  2. Click on the link generated in step 1.
  3. Observe nothing happens

Expected behavior

Download of the linked resource should initiate.

Platform and Versions (required):

Operating System - Arch Linux, version Unknown X64

Node.js environment
  Node.js - 16.5.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 7.17.0
  yarn - 1.22.10

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/node_modules
/public
/src
/.git
/src-tauri

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../public
  devPath - http://localhost:3001

Additional context

If a valid navigable URL (eg https://duckduckgo.com/) is used as the href of an a tag with the download attribute set, clicking the resultant link navigates to the given URL instead of downloading the content there.

@bdjnk
Copy link
Author

bdjnk commented Jul 18, 2021

@lemarier, can you explain why this is a good first issue? I'm struggling to figure how to approach it.

@lemarier
Copy link
Member

lemarier commented Jul 19, 2021

@lemarier, can you explain why this is a good first issue? I'm struggling to figure how to approach it.

It's been tagged as a good first issue mainly because I think it's a good way to jump in the Tauri stack and play with all dependencies (webview, javascript, etc..) and it affects all operating systems.

But I do agree it's quite complex, especially on macOS.

There are some references for WKWebview;

@lemarier lemarier transferred this issue from tauri-apps/tauri Jul 19, 2021
@lemarier lemarier added help wanted Help is requested to fix this issue platform: macOS type: bug and removed platform: macOS labels Jul 19, 2021
@wusyong
Copy link
Member

wusyong commented Jul 20, 2021

Looks like webkitgtk has API for it, but the rust crate doesn't provide any method other than constructor.
And webview2 only has experimental function for it.

@wusyong wusyong changed the title download attribute on link ignored Add download link support Jul 21, 2021
OJFord added a commit to OJFord/amail that referenced this issue Oct 2, 2021
Unfortunately download not implemented in tauri yet:
tauri-apps/wry#349
@nothingismagick
Copy link
Member

@wusyong - think we'd have time to pick this back up again?

@lucasfernog
Copy link
Member

I believe this is handled by #530 @nothingismagick

@atlanticaccent
Copy link
Contributor

With #530 merged I believe this issue has been addressed completely. Notably, it includes examples for handling "normal" downloads and blob downloads, which happen to be different enough to require separate solutions.

@lucasfernog
Copy link
Member

Nice! Let's try to add this to Tauri v1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Help is requested to fix this issue platform: All type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants