Reputation: 87
Hi I am trying to download file through unusual process.
The situation is as follows:
a user trigger download button.
the user select download directory.
web browser aggregate whole information of the user from third-party server
when the aggregating is completed the user will download the information automatically.
The problem is that download destination is determined before starting of download.
Is there any method to treat this issue?
Thank you in advance.
Upvotes: 1
Views: 429
Reputation: 29257
You can't set the distention folder. But as far as I understand your question is not the big issue but the downloading after you end the process.
If so, the steps will be: the user click, the data will send, the saved folder will be chosen by the user, the download will be start.
So, to start a download when you want (after the data will sent), you can create a hidden link with download
attribute then, click on it whenever you want.
Like this: (The downloaded file is demy of course, you need to set the link, the real URL).
function startDownload() {
$('#status').html('collect data..')
setTimeout(function(){
download('test content', 'file name.txt', 'text/plain');
}, 2000);
}
function download(text, name, type) {
var file = new Blob([text], {type: type})
$('<a href="' + URL.createObjectURL(file) + '" download></a>').get(0).click();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="startDownload()">Download</button>
<div id="status"></div>
http://output.jsbin.com/sihibu
Upvotes: 1
Reputation: 562
It is the clients browser which determines where downloaded files are saved, It can be an incredible security issue if the supplying website could change where that file went. You could send them off to system folders, or hide malicious code all over someones HDD.
The only way to set the download destination is in your browser configuration as far as my experience
Upvotes: 1