Download a File At Different Location Using Html5

Download A File At Different Location Using HTML5

It's not possible because this poses a security risk. People use fairly real information for their folder structure and accessing the folder names in itself poses an immediate risk. As described here:

Get browser download path with javascript

Most OSs tend to just default to a Download location and this is something the user decides through the Browser they use. Not the website.

In Chrome, Download location setting can be found at chrome://settings/downloads

How do I allow files to be downloaded to a folder other than the Downloads folder?

Its not possible as the download location is controller by the browser.

If you want to know more give the page a read Download A File At Different Location Using HTML5

Using HTML5/JavaScript to generate and save a file

OK, creating a data:URI definitely does the trick for me, thanks to Matthew and Dennkster pointing that option out! Here is basically how I do it:

1) get all the content into a string called "content" (e.g. by creating it there initially or by reading innerHTML of the tag of an already built page).

2) Build the data URI:

uriContent = "data:application/octet-stream," + encodeURIComponent(content);

There will be length limitations depending on browser type etc., but e.g. Firefox 3.6.12 works until at least 256k. Encoding in Base64 instead using encodeURIComponent might make things more efficient, but for me that was ok.

3) open a new window and "redirect" it to this URI prompts for a download location of my JavaScript generated page:

newWindow = window.open(uriContent, 'neuesDokument');

That's it.

How to specify download location in Html using JavaScript

Whether the browser asks the user or not is down to the preferences in the browser.

You can't bypass those preference, otherwise it would violate user's security.

What you can do is make sure you're sending the browser as much information as possible to help it make for a good user experience. If you're not already doing so, be sure to include a Content-Disposition header in the response to the download request, including a filename field:

Content-Disposition: attachment; filename=test.csv

Also see these other stackoverflow questions:

  Specify default download folder - possibly with JavaScript?

  Set file download destination using ExtJs

How to trigger a file download when clicking an HTML button or JavaScript

For the button you can do

<form method="get" action="file.doc">
<button type="submit">Download!</button>
</form>


Related Topics



Leave a reply



Submit