Skip to content

Instantly share code, notes, and snippets.

@montyr75
Last active June 17, 2016 17:05
Show Gist options
  • Save montyr75/e61180b3ff206a693538 to your computer and use it in GitHub Desktop.
Save montyr75/e61180b3ff206a693538 to your computer and use it in GitHub Desktop.
Automatically send a string in the form of a downloaded file to a browser client using new HTML5 anchor attributes.
void downloadFileToClient(String filename, String text) {
AnchorElement tempLink = document.createElement('a');
tempLink
..attributes['href'] = 'data:text/plain;charset=utf-8,${Uri.encodeComponent(text)}'
..attributes['download'] = filename
..click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment