I've got a JSON file on AWS s3. I want to make a flutter button to trigger a download of that file from the URL. I've looked around stack quite a bit and I find ways to download JSON generated data but not from a URL. I did think this one was promising:
But I can't seem to get it working in flutter. Here's what I'm doing to try to use anchor with "download" attribute.
First off, my URL looks like this (this is fake though just for the sake of public stack question)
Then I found this answer:
I tried this but it still (in Chrome Version 80.0.3987.149 (Official Build) (64-bit) shows the JSON in the browser rather than allowing me to save as a file directly on first click of the flutter button.
My flutter code looks like:
child: RaisedButton(
elevation: 1.0,
onPressed: () =>
downloadFile("https://myfirmware.s3.amazonaws.com/proxy/version.json"),
child: Text("Proxy Config File")),
My import is:
import 'package:universal_html/html.dart' as html;
And that method is:
void downloadFile(String url){
html.AnchorElement anchorElement = new html.AnchorElement();
anchorElement.href = url;
anchorElement.download = 'test.json';
anchorElement.click();
}
I am not sure how to see how this gets converted when building flutter for the web. But I was hoping this would look a lot like they mentioned here:
Which is:
<a href="http://example.com/media.mp3" download="check this out.mp3">Download Your File</a>