Upload files to SPA

How to configure file upload in a single page application without rebooting?

I had a situation where a PDF file is generated on the server and must be provided to the client for download. Sending it as an application / octet stream does not help anything in SPA, because files cannot be sent via AJAX .

The best I came up with is to save the generated file in a temporary folder on the server by sending the URL to the client and doing window.open(url) . The problem is that different browsers open files differently. Firefox, for example, opens PDF files in one tab by default, using their PDF.js , violating the whole idea of ​​SPA. But executing window.open(url, '_blank') often causes pop-up blockers, etc. Other types of files may cause God to know that ...

Is there a cross-browser, secure, general method for uploading files to the SPA?

+7
javascript single-page-application
source share
1 answer

In a SPA application, I wrote some time ago that window.location.href = '...' did the trick and worked correctly for most browsers, but the title of the contentType and content-disposition of the loaded page is of great importance. if the browser can recognize the file as the type that will be downloaded, then the likelihood that the spa will not break during redirection. In addition, only quick notes, such as Angular, sometimes allow target='_new' and target='_self' for their tags without interfering with routes, etc.

+4
source share

All Articles