hussain hussain - 3 months ago 11
Javascript Question

How to prompt save as option for user to download file using chrome?

I have method that is downloading file whenever this method called it is working as expected, I just see difference in browser in IE user has option to save As file but in chrome it directly download the file , How can we have that feature in chrome so user can use Save as option while saving the file so they can name the file ?

ctrl.js

function deleteFile(filename){
DitFactory.getFile(filename).then(function(response,$window){
console.log('data for download', response);
var data = JSON.stringify(response.data);
var blob = new Blob([data], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(blob, 'server.log');
socket.emit('stopRecording',$scope.filename);
});
}

Answer

What you are asking isn't possible.
It's a user preference

enter image description here

ref: http://www.howtogeek.com/231002/how-to-change-the-chrome-download-folder-location/

The only thing you can do is letting the user rename server.log inside a input element or a window.prompt before saving

saveAs(blob, prompt('Filename?', 'server.log') || 'server.log');
Comments