nette.ajax.js icon indicating copy to clipboard operation
nette.ajax.js copied to clipboard

File download in POST response

Open castamir opened this issue 10 years ago • 2 comments

I have a form where user choose to download (or send to email) a subset of financial statement documents.

If user choose send to email, everything is fine, but if he picks download, then no file is downloaded (without ajax, file is downloaded successfully).

If I modify form signal to use redirect where I use the same way i did in the form signal (sending FileResponse), then it allows me to download that file, but spinner stops spinning due to window.location.href in redirect extension. I have experimented and figured out that using window.open() will keep spinner (and all gif animatins) unharmed, but browser's anti-popups alert shows up.

Any ideas for a workaround? I simply need a file download request from within a form with a spinner spinning for each request until requested file is downloaded.

castamir avatar Oct 07 '14 11:10 castamir

If I get it right, it's redirect extension that makes trouble to you, right? What about disabling it for that given request with data-ajax-off/settings.off?

vojtech-dobes avatar Jan 17 '15 21:01 vojtech-dobes

When sending new FileResponse( ... ) from nette, instead of forcing the download of the file, it sends the file represented as a string (see http://prntscr.com/9azo8u).

public function handleDownload() {
   $this->presenter->sendResponse(
   new FileResponse(
      $this->version->getPath()
   ));
}

This works fine without ajax.

Here are sent headers for the ajax request (which i think are correct):

Content-Disposition:attachment; filename="test.rar"; filename*=utf-8''test.rar
Content-Length:1673291
Content-Range:bytes 0-1673290/1673291
Content-Type:application/octet-stream

alesmenzel avatar Dec 06 '15 15:12 alesmenzel