How to show the progress bar when creating a PDF file for download, without IE warnings "download"

I have a connection between client and server. The process is simple:

  • I am making an AJAX POST request to a controller that generates a PDF file in the file system.
  • Upon successful completion of the above request, the GET request form opens to return the PDF file, and the "Save or open" dialog box opens in the browser.

The reason I have a two-step process is because I need to create a progress bar when creating a PDF file.

The reason for the second request is to submit the form, and not part of the AJAX request, because I cannot get the standard browser save or open dialog box.

The problem with this approach is that IE7 and IE8 cause an annoying notification bar to notify the user that it is dangerous to download the content, and I don't want this.

So:

  • I need a progress bar.
  • If I go to an AJAX request, I need a way to open the Save or Open dialog box.
  • If I switch to the GET submit form, I need to know when the file was generated to stop the progress bar, something like a common flag between the server and the client.

Any help was appreciated.

+4
source share
1 answer

One possible (some anti-patterns) workaround is this, but it's not a great design, probably

However, I have seen this (and admit that I did it) before, and, except for some guilt, he did the trick

  • the user clicks the link that goes to the servlet that generates the PDF, and will just wait (timeout settings should be applied) until he is ready ... (Content-Disposition header, etc.), as usual download

  • Servlet will report the progress of a shared session variable when creating a PDF

  • AJAX call to the server will read progress from the session variable and show the user

  • when the PDF is completed, the browser will simply download it (there may be a risk of request timeout)

The main problem here is to use the request stream as a workflow and block it, which may give this answer a couple of downvotes ...

I am not familiar with Message Driven Beans, but this is a different, possibly better solution.

+3
source

Source: https://habr.com/ru/post/1411805/


All Articles