How to download web client side data as a file using darts

I have some data about the client web browser (text box) in my Dart Polymer web application. I would like to allow the User to download the text as a file. How can i do this? I do not want to use server side code.

+6
source share
1 answer

Client-side downloads can be performed with the following code:

void downloadFileToClient(String filename, String text){ AnchorElement tl = document.createElement('a'); tl..attributes['href'] = 'data:text/plain;charset=utf-8,' + Uri.encodeComponent(text) ..attributes['download'] = filename ..click(); } 

It depends on the browser support for the download attribute on the anchor tags. Check the target platform for suitability.

The CanIUse site provides status for platforms and browser versions.

+6
source

Source: https://habr.com/ru/post/955051/


All Articles