0

I want users of my web page to be capable of downloading a file based on some input data. This input data can be quite large, so it cannot be through a GET request. Instead I chose a POST request, by creating a form with the download url as the action and method POST. As soon as the form is submitted the file is downloaded.

This works perfectly well in IE, Edge, Safari and Chrome, but in Firefox the page that the form is on is actually cleared. The download is still working, but users have to reload the page in order to do a new download, if they want.

I can imagine this is browser dependent and might be normal behavior as we're actually triggering the browser to load another page, but still I'm looking for a way to make Firefox behave like the other browser, e.g. download the file only while leaving the original page intact.

The file download url is actually a Java HttpServlet that writes bytes to response's outputstream. The response contains, i.m.o., the correct headers:

  • Content-Disposition: "Attachment; filename=file.ext"
  • Content-Length: "5352"
  • Content-Type: "application/octet-stream;charset=UTF-8" (also tried with text/plain and text/xml)
Tohnmeister
  • 468
  • 1
  • 5
  • 14

1 Answers1

0

After posting this, I figured the best way to describe my problem to Google was "submit form and stay on same page", which led me to this StackOverflow question and working answers.

Community
  • 1
  • 1
Tohnmeister
  • 468
  • 1
  • 5
  • 14