My goal is to download a csv file from dynamic content handled by Angularjs. The file is constructed server side by Django.
It is easy to get a file with Django. We only need a view to return an HttpResponse (doc). On the client side, I can then get it by changing the browser's url with $window.location.href
.
If I have a few parameters, I can give them as query parameters to window.location with search
(Mozilla doc).
However I must pass a large list of data to the server, so I can't use query parameters. (I'm limited by the max length of urls).
With AngularJS' $http
, we can set a lot more config to a GET, including data parameters: doc. This data is "to be sent as the request message data", it is not encoded to the url. I'd like to use that.
So, my pb would be solved if I could set this data with the $window.location.href
call. Is it possible ?
If I fire a GET with Angular's $http
, Django's HttpResponse
isn't interpreted as a response, it is intercepted as data into the success
clause. How can I make use of it ?
Do you see another strategy to create and download dynamic files ?
edit: I went with this for a csv file.
other strategies ideas:
- create a file server side and return its url (django: manage files)
- we can use a form. That really seems the simplest though.
Many thanks !