wave icon indicating copy to clipboard operation
wave copied to clipboard

Links don't download when button is True

Open mtanco opened this issue 3 years ago • 10 comments

Wave SDK Version, OS

Wave 0.17.0 safari & chrome

Actual behavior

When using ui.link(download=True, button=True) the file opens in a new tab but is not actually downloaded locally. When button=False the file downloads as expected

Expected behavior

File to download

mtanco avatar Sep 14 '21 23:09 mtanco

Citing docs on download attribute:

True if the link should prompt the user to save the linked URL instead of navigating to it. Works only if button() is false.

mturoci avatar Sep 16 '21 07:09 mturoci

Would love to know why this is a functionality? A download button seems like a common UI element.

mtanco avatar Sep 16 '21 15:09 mtanco

@mturoci A button with a download attribute would be useful.

lo5 avatar Sep 17 '21 02:09 lo5

Agree, just wasn't sure if there isn't any non-obvious reason for this from your side @lo5. The implementation should be a no-brainer, will do.

mturoci avatar Sep 17 '21 05:09 mturoci

@mtanco can you please put up a small repro?

I managed to download with a button link like so:

ui.link(
    label='Download link',
    path='https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc',
    download=True,
    button=True
)

mturoci avatar Sep 17 '21 12:09 mturoci

@mturoci it doesn't work for me

Daniel-Kelvich avatar Jun 09 '22 11:06 Daniel-Kelvich

@Daniel-Kelvich can you add a min repro code please? Thanks!

mturoci avatar Jun 09 '22 13:06 mturoci

@mturoci sure

from h2o_wave import main, app, Q, ui

@app('/downloads')
async def serve(q: Q):
    download_path, = await q.site.upload(['data/img.png'])
    q.page['download'] = ui.form_card(box='1 1 2 2', items = [
        ui.link(label='Download Results', path=download_path, download=True, button=True),
    ])

    await q.page.save()

Daniel-Kelvich avatar Jun 12 '22 19:06 Daniel-Kelvich

The current state of download attr is:

  • If the resource can be opened by the browser itself (jpg/pdf etc.), open it in browser.
  • If the resource cannot be opened by the browser (.docx etc.), download it.

The reason was bug in Firefox that dropped websocket connection when clicking the link with download attribute. It may be fixed in newer versions though so worth revisiting for sure.

mturoci avatar Jun 13 '22 09:06 mturoci

Is there a way to force a download irrespective of format? Or at least open in a new tab? Was facing a similar issue while using .json files.

Particularly because when the file is opened in browser, there is no way to go back to the app without refreshing it (losing saved arguments in the process).

cc: @Nischaydnk

vopani avatar Aug 12 '22 05:08 vopani

Or at least open in a new tab?

Yes, this should be possible via target attribute.

It seems like I managed to get the download work consistently across browsers. Should be possible in the next release.

mturoci avatar Jan 09 '23 11:01 mturoci

My use-case is a download through meta's redirect : https://github.com/vopani/waveton/blob/main/apps/data_apps/image_annotation/app.py#L284

vopani avatar Jan 09 '23 11:01 vopani

Download through meta's redirect is more of a hack than a real solution as it should be used for redirects.

I think we should provide a native way of forcing the download programmatically, something like meta.download. Could you please file a separate feature request? This one deals with downloads after the user clicked.

mturoci avatar Jan 09 '23 12:01 mturoci