I am trying to get the Vec<u8>
or String
(or more ideally a Blob ObjectURL) of a file uploaded as triggered by a button click.
I am guessing this will require an invisible <input>
somewhere in the DOM but I can't figure out how to leverage web_sys
and/or gloo
to either get the contents nor a Blob ObjectURL.
A js-triggered input probably won't do the trick, as many browsers won't let you trigger a file input from JS, for good reasons. You can use
label
s to hid the input if you think it is ugly. Other than that, you need to wiggle yourself through thefiles
api ofHtmlInputElement
. Pretty painful, that:(If you've got questions about the code, ask. But it's too much to explain it in detail.)
And extra, the features you need on
web-sys
for this to work:If you're using
gloo
with thefutures
feature enabled, the second function can be implemented much more neatly: