Download and open a file by javascript - javascript

I am making a SPA.
I want to download a file (e.g. .xlsx) and open a "Open With" dialog like this, by javascript.
Or open the file on client's PC.
Is there a way to solve this?
I know javascript cannot access to local files without
<input type="file">.
I want any advice. (even THIS IS IMPOSSIBLE)

I'm assuming your SPA has an API? Well, you need to the direct the user to an API endpoint that will create and then send to the client the .xlsx file.
You can use the Content-Disposition header to control how the browser will open the file.
Kind regards,

Related

add print and download protected pdf viewer to web site

Is there any way to add slide share like PDF viewer to the web site?
Only users can be able to view document... print or download can't be done.I tried several JavaScript plugins for doing that but unable to find one that has no print and downloadable options. And also client can disable JavaScript in browser therefore I think of that suitable server side script.
I also unable to find a server side script (PHP) for this. Please suggest.
Just keep the file outside the web root directory because the web browser follows the local file system privileges and not its own. Put them into a directory with a .htaccess file that blocks all communication.
Ex: Order deny,allow
deny from all
I don't know how much it will gonna help you.

Copy local file to another location with a web page

I do not know if this is possible to do.
What I want to achieve is a web page (online) where once you select an image from my pc via a classical input in html, let me copy it to another folder always inside of my PC (or a PC connected to the network local).
I can do this thing? Maybe with javascript?
There are other possible solutions?
Thanks.
You cannot do this. Websites have no permission to access Your computer local system. With HTML <input type="file"> You can only send files to the chosen website directory. Eventually, You can download those files later and put them on the other place in Your system.

TinyMCE windowManager.open() secure PHP script

I am using TinyMCE's activeEditor.windowManager.open() method to implement my own file browser. It opens a PHP script that does the file uploads/browser.
My concern is that anyone looking at the JavaScript will know the URL to my script and be able to open it in any browser window. I wouldn't want that because only admins to my web app should be able to upload or manage/delete stuff.
I have tried checking for $_SERVER['HTTP_REFERER'] in my file browser script, but I think this is not foolproof.
Any ideas how this can be made more secure?

Download file without opening download dialog

The Problem:
I need to force the download dialog not to open in a browser when in a downloading process:
I have the server code like any other download servlet.
On the client side I have a link that points to the servlet like any other download link.
Is there a way to download automatically when clicking on the link without opening the dialog?
What I think is that it may be related to the following:
Server code (Java) ?
Client code (JavaScript) ?
Browser settings ?
Browser type ?
The Purpose behind this:
There is a website that belongs to this company where it is fortified with a high security wall clearing out the chance of downloading any virus.
The clients of this site need to have the download link saving automatically when clicked on.
No, you can't interact with files on HDD from a browser without notifying the user. It's a security policy.
If I understand well, you want the browser to download your file on a default folder without asking you where?
Well, I think that, this depends on your browser, maybe you can customize the configuration in order to set a default download folder, but, I think it is not possible to force it on the server side.

Browser download file prompt using JavaScript

I was wondering if there was any method to implement browser's download file prompt using JavaScript.
My reason - well users will be uploading files to a local fileserver which cannot be accessed from the webserver. In other words, both will be on different domains!
For example, let’s say websites hosted on www.xyz.com, but files would reside on local file server with address like \\10.10.10.01\Files\file.txt. How am I uploading/transferring file to local fileserver... using ActiveX and VBscript! (don’t ask :-)
So I am storing local file path in my database and binding that data to a grid. When the user clicks on that link, the file opens in a window (using JavaScript).
Problem is certain file types like text, jpg, pdf, etc. open inside browser window. How would I be able to implement content-type or content-disposition using client side scripting? Is that even possible?
EDIT:
the local file server has a window's shared folder on which the files are saved.
"content-disposition: attachment" is pretty much the only way to force that, and this MUST be set in the response header.
If the file is hosted on a web server like in your example, you can do:
window.location.replace(fileUrl);
.. and the browser will figure out what to do with the file. This works great for most files, such as .xls, .csv, etc, but keep in mind that this isn't full-proof because the user's MIME handler settings will determine what to do with the file... i.e. if it is a .txt file it will most likely just be displayed in the browser and will not be given a "file download" dialogue box.
As of August 2015, adding the "download" attribute to your tag enables the behavior you're looking for, at least in Chrome.
You could try using a plain hyperlink with type="application/octet-stream". Seems to work in FF, but IE and Opera ignore the attribute.

Categories

Resources