Unable to download pdf blob url on Safari -
currently using filereader open , view pdf works on chrome. however, when pdf opened on safari , click download button, nothing happens.
var reader = new filereader(); reader.onloadend = function(e) { $window.location.href = reader.result; } reader.readasdataurl(file);
after having spent entire day working on similar issue, understood problem can share knowledge you.
basically, kind of problems generated when render blob
inside opened browser tab page url changes in like:
blob:http://localhost:8080/9bbeffe1-b0e8-485d-a8bd-3ae3ad9a0a51
the wrong procedure requiring pdf this:
var fileblob = new blob([response.data], {type: 'application/pdf'}); window.location.hfref = fileblob;
why doesn't work? well, can see pdf rendered on page might fooled thinking pdf loaded fine. however, if either try refresh page or download pdf on machine, doesn't work.
wth? so, thinking of sort of black magic going around browser, figured out problem: file doesn't exist cache stored inside browser. so, when generate blob , redirect current tab point generated blob url, lose cache.
now makes sense right?
- you request file on server
- the browser stores buffer inside tab
- you point page url read buffer
- you see pdf @ same time, lose buffer information
the think can do, opening blob url in new tab with:
window.open(fileblob, '_blank');
problem solved.
Comments
Post a Comment