0

How can I provide the user of a web-app with a download-link to programmatically created data in AngularDart?

I thought this would be an easy task, since the download of data could be handled via data-links. But it turns out that AngluarDart doesn't let me use data-links since they are considered unsecure. In a pure Javascript environment I would use Filesaver.js, but also this is not possible with AngularDart (at least I didn't find a way to use it there).

What I really want to do: I create data in the app with code. At the end i have a json-structure that needs to be downloaded to the client computer of the user. He should be presented with a file select dialog where he can enter a filename and then the data should be saved there. And this should be initiated by a click on a button.

Up to now i didn't find a working way to make this happen in AngularDart. I tried BrowserClient, a-tags with download attribute, forms with data-url, but nothing works.

If anybody could give me a hint how to make this work, I would be very happy. A hint on how to use Javascript-Libraries (like FileSaver.js) in AngularDart would also be welcome.

I don't use Flutter and also I need this to work in the browser. So File from dart:io is no solution for me (this will be one of the first things you find, when searching for a solution). Also it is no solution to save the file to the server and download it to the client.

zreptil
  • 230
  • 3
  • 13
  • if you use data-links such as [here](https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-not-through-server), what errors do you get? – Mattia Jun 30 '20 at 12:44
  • AngularDart changes the data-url to unsafe: so they are not working. I know that there is a workaround with a sanitizer, but this is like hacking the app and involves the breaking of security-considerations. I thought there must be an easier and standardized solution for such a (in my eyes) common task. – zreptil Jul 03 '20 at 04:48
  • Hard to help you without code snippet, but did you try to inject `DomSanitizationService` and use `bypassSecurityTrustUrl` method ? (see docs https://pub.dev/documentation/angular/latest/angular.security/DomSanitizationService-class.html#constructors) – Hadrien Lejard Jul 03 '20 at 12:58
  • I need a code snippet and don't have one ^^ As said in the comment before, the DomSanitizationService seems to me like I break the security concept of AngularDart. If there really, really, really is no other way, I will try this. But still I wonder, why there is no easy way to achieve this, without circumventing the security concept. – zreptil Jul 03 '20 at 13:12

0 Answers0