I've been struggling with this problem for the last 2 days, and would really appreciate some guidance. I have a Spring back end serving a .dmp file to the angularjs client. I was passing with octet-stream but for some reason the data gets scrambled. Here is the diff (http://ift.tt/2dV9vNF) of the bit, left is correct, right is what the client receives. You can see there's some resemblance but looks there are random characters inserted or something.
Server
@RequestMapping(value = "/{path}/{fileName}/downloadFiles", method = {RequestMethod.GET})
public void download(HttpServletResponse response,
@PathVariable("fileName") String fileName,
@PathVariable("path") String path) throws Exception {
File file = new File(configuration.getExceptionDir() + File.separator + "clientLogs" + File.separator + path + File.separator + fileName);
InputStream is;
is = new FileInputStream(file);
response.setContentType("application/octet-stream");
response.addHeader("Content-disposition", "attachment; filename=" + fileName);
IOUtils.copy(is, response.getOutputStream());
response.flushBuffer();
is.close();
}
Client
$http({
method: 'GET',
url: '/web/admin/storeFailures/' + directory + '/' + fileName + '/downloadFiles/'
}).success(function (response) {
var file = new File([response], fileName, {type: 'application/octet-stream'});
saveAs(file);
})
Response header
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-disposition:attachment; filename=yexing.yang_10-0-14393-0_2016-10-03-16-57-34.dmp
Content-Type:application/x-download
Date:Thu, 06 Oct 2016 15:06:49 GMT
Expires:0
Pragma:no-cache
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-XSS-Protection:1; mode=block
Request header
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:JSESSIONID=83410DE21F2EE5D7CFB196AFBFC3C5C3; itemsPerPage=15; jobStatuses=%7B%22PREPARING%22%3Afalse%2C%22SCHEDULED%22%3Afalse%2C%22INPROGRESS%22%3Atrue%2C%22COMPLETED%22%3Atrue%2C%22FAILED%22%3Atrue%2C%22CANCELLED%22%3Atrue%7D; jobTypes=%7B%22EXPORTSERIES%22%3Atrue%2C%22EXPORTSTUDY%22%3Atrue%2C%22INDEX%22%3Atrue%2C%22REINDEX%22%3Atrue%2C%22REIMPORTCCD%22%3Atrue%2C%22REIMPORTDICOM%22%3Atrue%2C%22REIMPORTEXAM%22%3Atrue%2C%22REIMPORTHL7%22%3Atrue%2C%22RETRIEVE%22%3Atrue%2C%22AUTOQR%22%3Atrue%2C%22CDAQUERY%22%3Atrue%2C%22STORAGECOMMIT%22%3Atrue%2C%22ANALYSIS%22%3Afalse%2C%22DELETESERIES%22%3Atrue%2C%22DELETEEXAMS%22%3Atrue%2C%22ANONYMIZE%22%3Atrue%2C%22BACKUPEXAMS%22%3Atrue%2C%22DELETEHL7%22%3Atrue%2C%22BACKUPND%22%3Atrue%7D; myTheme=%22bootstrap-darkly.min.css%22; myThemeName=%22darkly%22; showAnalysis=false; showScheduled=true
Host:localhost:8080
Referer:http://localhost:8080/web/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Aucun commentaire:
Enregistrer un commentaire