1

I have a button on my web app which when clicked generates a text file based on user inputs. For this i use ajax that send parameters to spring backend. This works. What I want is on the same button when clicked generated file to be downloaded on user computer.

Can this be done without storing the file on server and generating link ?

xMilos
  • 1,519
  • 4
  • 21
  • 36
  • can [this elder post](https://stackoverflow.com/questions/5673260/downloading-a-file-from-spring-controllers) help you? – Foo Bar Jun 08 '17 at 11:08
  • Can you not return the file stream from the original call and dump it into an iframe? – Nope Jun 08 '17 at 11:09
  • Check: "Create a file in memory for user to download, not through server" | https://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server – yuriy636 Jun 08 '17 at 11:10
  • @FooBar that looks promising i will test it – xMilos Jun 08 '17 at 11:18
  • @yuriy636 already saw that i think it is risky as not all browsers are supported – xMilos Jun 08 '17 at 11:18

1 Answers1

1

Maybe data-URI can help you for presenting a download link to the user:

<a href="data:text/plain,this is some text" download="some-filename.txt" target="_blank">Download<a>

for more information see Mozilla: Data-URI

credits to the original answer

Sebastian
  • 451
  • 6
  • 19