Flutter web file download

788 views
Skip to first unread message

Travis Dixon

unread,
Dec 30, 2019, 2:46:11 PM12/30/19
to Flutter Development (flutter-dev)
So I've got a service that requires a HTTP GET with a Bearer token in the authorization header, which responds with a file.

What I want, is for the app to pop up the browsers standard file save dialog and download the file.

I've tried searching around a bit and so far can only find references to saving on mobile devices and the odd post reminding me that I can't use dart:io from the web.

Has anyone done this before, or know a likely avenue of approach? 

I'm currently thinking that I'll likely have to do some javascript voodoo involving file URLs (though I'd rather not, some of these files can be large-ish, 10's of MB)

Travis Dixon

unread,
Dec 30, 2019, 4:09:29 PM12/30/19
to Flutter Development (flutter-dev)
Well, as a temporary work around I've modified the service to accept bearer tokens as a query string parameter, which allows for a solution using html anchor tags:

I attempted the http://user:password@url mechanism but it appears to be deprecated/unsupported in a lot of browsers now.

The above component has the unfortunate side effect that it navigates away from the app if there's any sort of error, so maybe I could get it to target a new window to improve that.

Anyhow, it's serviceable, however setting the header correctly is still an open question
Reply all
Reply to author
Forward
0 new messages