I read many questions and answers from my problem but I did't found solution. I try to download file and when I get file , that is Object .. how I can take name of that file?
my get method:
this.downloadFile = function(data) {
return $http({
method:'get',
url:this.apiUploadFileUrl+"allFiles/"+data,
responseType:'arraybuffer'
});
};
on server side... a make response and Add file
File[] allFiles = projectFolder.listFiles();
File oneFile = allFiles[id];
path = oneFile.getAbsolutePath();
InputStream in = new FileInputStream(new File(path));
org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
response.flushBuffer();
in.close();
and here i get file which I wont to download, but how to take name of the file ?
uploadFileRestServices.downloadAllFiles(data)
.success(function(databack,response,status,data) {
var file = new Blob([ databack ], {
type : 'application/csv'
});
var fileURL = URL.createObjectURL(file);
var a = document.createElement('a');
a.href = fileURL;
a.target = 'filename';
a.download = "lll.txt";
document.body.appendChild(a);
a.click(); })
.error(function() {
alert("error");
});
I got file but only I don't know how to take name of that object(file) ... OR... Because on server side I know filename , can I somewhere in response put file name(header or....) and how on angular side to take that attribut ???
I use AngularJS, REST, Spring ...
Thanks in advance for any help.