Genie Discord forum
![Author Avatar](https://cdn.discordapp.com/avatars/679661866166910986/f3ed85f7a3e27b92039307687c03613a.png?size=512)
In my app, users can download (tarballed) files from the server.
Right now, my implementation looks like this:
btn(class = "q-mt-lg", "Download data", color = "primary", href="data", download=string(round(now(), Second(1)), ".tar"))
where data
is a route that returns a tarball with the files compressed in it.
I have two questions:
- Is there a "
downloader
" component equivalent to the already existinguploader
component? - Once the user downloaded the data, I would like to have the downloaded files deleted. Is there some kind of post-action I can define in the implementation that deletes the files only after a successful download? Something like
btn(..., onsuccess = my_delete_files_function())
![Author Avatar](https://cdn.discordapp.com/avatars/743412727464067154/bc30abeb49653e9978c0f7c90f4486a8.png?size=512)
There is no download component that I know of, and I just found out that you can add href and download properties to a btn π
Today @hhaensel added a new Stipple plugin to trigger downloads from the backend
https://github.com/GenieFramework/StippleDownloads.jl
You could use this to serve the file and delete it right after
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
@yakir12 It's in the process of being registered, so you need to dev it if you can't wait to try it out. If you can't figure out how to use it for your case, don't hesitate to open an issue. If you think, your use case should be mentioned in the README let me know
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
A static file ca be passed to data by read(filename)...
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
I should probably add a method for passing IOBuffers
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
It would save you a take!()
![Author Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Thatβs really great! Iβm wondering how to implement that when we have 500+ concurrent users, each file should have a distinct name depending on a session correct? I suppose this could be done by event"_client"?
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
That's not completely correct. The _client is only there to differentiate between different clients with the same channel,say the same user with the same browser logged in twice
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
All users can receive different files under the identical name. But you are free to chose it.
![Author Avatar](https://cdn.discordapp.com/avatars/679661866166910986/f3ed85f7a3e27b92039307687c03613a.png?size=512)
This worked very nicely. Thanks a lot!
Here's my MWE to test my specific needs (i.e. deleting the files after a successful download):
using Stipple, Stipple.ReactiveTools
using StippleUI
using StippleDownloads
import Stipple.opts
@app begin
@event download_file begin
file = tempname(".", cleanup=false)
open(file, "w") do io
write(io, rand(UInt8, 1000))
end
try
download_binary(__model__, read(rand(Bool) ? file : wrong_variable_name), "binary"; client = event["_client"])
@info "download worked, deleting file"
rm(file)
catch ex
@warn ex
@warn "download failed, not delteing file"
end
end
end
function ui()
row(cell(class = "st-module", [
row([
cell(btn(class = "q-ml-lg", "Download and delete file", icon = "download", @on(:click, :download_file, :addclient), color = "primary", nocaps = true))
])
]))
end
@page("/", ui)
up(open_browser = true)
![Author Avatar](https://cdn.discordapp.com/avatars/679661866166910986/f3ed85f7a3e27b92039307687c03613a.png?size=512)
You ask and you shall receive... https://github.com/GenieFramework/StippleDownloads.jl/issues/1 π
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
I answered in the issue; basically you have to move the event handler out of the @app
macro ...
![Author Avatar](https://cdn.discordapp.com/avatars/679661866166910986/f3ed85f7a3e27b92039307687c03613a.png?size=512)
yap, and it worked and I closed the issue. Perfect! Thank you so much π