Question

Is it possible to get the browser to popup its Save As... dialog when doing a POST (rather than GET) request?

Using the Spring framework, I'm trying to build a service that will receive some data (a two-dimensional json array), and produce an Excel file that the user is prompted to download.

By doing a GET request, eg by browsing directly to my URL, I can get the browser to display the popup by setting headers similar to this:

response.setHeader("Content-Disposition", "attachment; filename=" + fileName)
response.setContentType("application/vnd.ms-excel")

I need to allow the client to post the data that will be used to build the Excel file though, which implies a POST request. The same headers are returned, but no popup.

Is there a way to achieve this, or does the popup appear only for GET requests? I'm thinking I could do a two-step process; 1) allow the client to POST the data, and return some sort of reference key, 2) allow the client to do a GET request and include the key, and return the relevant headers to cause the browser to popup the dialog.

Any other thoughts on how to do this?

Thanks

Was it helpful?

Solution

It's possible. I'm not sure what I did wrong the first time I tried it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top