filesaver.js

how to save byte array as zip in angular

丶灬走出姿态 提交于 2021-01-29 14:00:56
问题 I'm trying to download (using FileSaver.saveAs) a byte array getting from the server (nodejs\express) as a zip. I'm manage to download it as zip, but it doesn't open (it is invalid). I had few miss-clarities regarding the way the data should be defined - content type, responseType both in the server and in the client, should I convert it to a blob, etc) - but I think I over-come them with the detailed below code. The problem is at the final function, in the exportAsZip function - the data

Angular 7 get corrupted file while downloading blob

淺唱寂寞╮ 提交于 2020-07-03 04:57:40
问题 Using Angular 7, i am calling api by posting the url file and try to download it by using 'saveAs' function from the fileSaver library. The file is downloading but it cannot be opened because it's corrupted . my call is the following: var file_url = (response as any).headers['Location'] + 'files/Data.xlsx'; var filename = 'Data_' + this.getDateService.getDateFile() + '.xlsx'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }), responseType:

IOS Safari - How to download or display a pdf

邮差的信 提交于 2020-01-24 20:12:19
问题 just a simple example, I tried using window.open var save = 'test' var blob = new Blob([save], { type: "application/pdf;charset=utf-8" }); var fileURL = URL.createObjectURL(blob); window.open(fileURL); I also tried using FileSaver.js var save = 'test' var blob = new Blob([save], { type: "application/pdf;charset=utf-8" }); saveAs(blob, filename); Assume the blob contains valid pdf content. It seems to work in all other browsers (including OSX safari) by downloading a pdf file. However in both

IOS Safari - How to download or display a pdf

别来无恙 提交于 2020-01-24 20:12:17
问题 just a simple example, I tried using window.open var save = 'test' var blob = new Blob([save], { type: "application/pdf;charset=utf-8" }); var fileURL = URL.createObjectURL(blob); window.open(fileURL); I also tried using FileSaver.js var save = 'test' var blob = new Blob([save], { type: "application/pdf;charset=utf-8" }); saveAs(blob, filename); Assume the blob contains valid pdf content. It seems to work in all other browsers (including OSX safari) by downloading a pdf file. However in both

Generate an image of a div and Save as

喜欢而已 提交于 2020-01-22 09:30:29
问题 I'd like to create an input button "Save image" that : take a screen shot of a div ask to "Save as" on the user's computer I've found how to create a screen of a dive using html2canvas and to open it in a new tab, it works perfectly : function printDiv2(div) { html2canvas((div), { onrendered: function(canvas) { var img = canvas.toDataURL(); window.open(img); } }); } But for thee Save as part, is a kind of the tough part... I've found interesting topics, as I'm new in JS (and object) coding, I

Generate an image of a div and Save as

我们两清 提交于 2020-01-22 09:29:54
问题 I'd like to create an input button "Save image" that : take a screen shot of a div ask to "Save as" on the user's computer I've found how to create a screen of a dive using html2canvas and to open it in a new tab, it works perfectly : function printDiv2(div) { html2canvas((div), { onrendered: function(canvas) { var img = canvas.toDataURL(); window.open(img); } }); } But for thee Save as part, is a kind of the tough part... I've found interesting topics, as I'm new in JS (and object) coding, I

Angular 8: Read from local storage, modify and save back to same file

旧巷老猫 提交于 2020-01-16 12:00:48
问题 I'm using the following code to read data from local storage on the client side: fileChange(event) { let file = event.target.files[0]; var reader = new FileReader(); reader.readAsText (file); reader.onload = () => { console.log (reader.result); } let fileSaverService = new FileSaverService; var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); fileSaverService.save (file, "hello.txt"); The contents in 'file' is saved to "hello.txt" This is not what I need. I want to

save excel file using FileSaver.js

ε祈祈猫儿з 提交于 2019-12-30 18:53:20
问题 I am trying to export data to excel in angular js 1) User clicks a button 2) Data in $scope.myArray gets saved to excel file. I tried var blob = new Blob($scope.myArray , { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" }); saveAs(blob, "Report.xls"); }; It prompts to open the excel file. But whenever I try to open it, it says the file format or file extension is not valid. Any Help! 回答1: Try the following code that will help you to create an excel

HTML5 File API downloading file from server and saving it in sandbox

假如想象 提交于 2019-12-28 03:19:06
问题 I'm trying to understand HTML5 API. I'm designing the web application where the browser client need to download multiple files from server; user will perform something with the downloaded files and the application than need to save the state on user hard-rive. I understand that the browser can save these files only to its sandbox which is fine as long as the user can retrieve those files on the second time he starts the application. Should I use BlobBuilder or FileSaver? I'm a bit lost here.

Allow to choose directory using Angular FileSaver.js

一个人想着一个人 提交于 2019-12-24 09:38:51
问题 I am using FileSaver.js to save files from Angular. However, I would like to allow the user to choose the directory. How can I do this? 回答1: I don't believe this is possible. It is the browser's choice whether to present the user with a "Save As.." dialog box, or whether to just automatically download to the "Downloads" folder. For example, here is the setting for Chrome that controls this behaviour: 来源: https://stackoverflow.com/questions/43240297/allow-to-choose-directory-using-angular