filesaver.js

AngularJS FileSaver producing empty file

ε祈祈猫儿з 提交于 2019-12-11 09:54:26
问题 I have the following PHP code which outputs a document from a web service: $db->where('documentReference', $post->documentID); $results = $db->getOne('documents'); $filelocation = 'doc/'; $file = $results['filename']; header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Length: ' . filesize($filelocation.$file)); header('Content-disposition: attachment; filename="'.$file.'"'); readfile($filelocation.$file); And on the front end..

XLSX File corrupted when sent from Node.js via Restify to Client

故事扮演 提交于 2019-12-10 23:56:48
问题 I am working on a project where I am creating an excel file using XLSX node.js library, sending it to a client via Restify where I then use the FileSaver.js library to save it on the local computer. When I write the xlsx workbook to file on the backend, it opens fine, however, when I open it on the client, it is corrupted. I get the error: "Excel cannot open this file. The file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension

Saving base64 image with Filesaver.js

两盒软妹~` 提交于 2019-12-09 01:26:40
问题 I am getting multiple Base64 URIs of JPG images. I need to save them as jpg files. I'm trying to use FileSaver.js, but its not working for me. I have used filesaver.js before, when I was getting images from aws-sdk, in which, the data was in buffer form and it worked. However, its not working for me with base64 string. var base64 = '/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gODUK

angular-file-saver download base64 file using FileSaver

青春壹個敷衍的年華 提交于 2019-12-08 12:04:03
问题 I'm trying to download a file that is base64 using angular-file-saver. I can do this without angular-file-saver with just this html mark-up: <a ng-href="data:{{document.mimeType}};base64,{{document.base64Code}}" target="_blank" download>Download Single Document</a> I have other needs now that are fulfilled with angular-file-saver that are causing me transition to doing this with FileSaver. Now I want to implement the same download using file saver. My html mark-up is: <a ng-href="#" ng-click=

How to use Jest to test file download?

拥有回忆 提交于 2019-12-07 06:49:20
问题 I have some code as below: /* global document */ /* global window */ /* global Blob */ import FileSaver from 'file-saver'; export const createDownloadFromBlob = (blob, filename, extension) => { FileSaver.saveAs(blob, `${filename}.${extension}`); }; export const createDownload = (content, filename, extension) => { createDownloadFromBlob(new Blob([content], { type: 'application/octet-stream' }), filename, extension); }; I want to use Jest to unit-test these two methods, but I don't know where

Download binary file with Axios

假如想象 提交于 2019-12-05 14:12:41
For example, downloading of PDF file: axios.get('/file.pdf', { responseType: 'arraybuffer', headers: { 'Accept': 'application/pdf' } }).then(response => { const blob = new Blob([response.data], { type: 'application/pdf', }); FileSaver.saveAs(blob, 'file.pdf'); }); The contend of downloaded file is: [object Object] What is wrong here? Why binary data not saving to file? I was able to create a workable gist (without using FileSaver) as below: axios.get("http://my-server:8080/reports/my-sample-report/", { responseType: 'arraybuffer', headers: { 'Content-Type': 'application/json', 'Accept':

How to use Jest to test file download?

孤街醉人 提交于 2019-12-05 10:12:48
I have some code as below: /* global document */ /* global window */ /* global Blob */ import FileSaver from 'file-saver'; export const createDownloadFromBlob = (blob, filename, extension) => { FileSaver.saveAs(blob, `${filename}.${extension}`); }; export const createDownload = (content, filename, extension) => { createDownloadFromBlob(new Blob([content], { type: 'application/octet-stream' }), filename, extension); }; I want to use Jest to unit-test these two methods, but I don't know where to start. Any help would be appreciated. I would mock out FileSaver with a spy: import FileSaver from

How to download an excel (xlsx) file using Angular 5 HttpClient get method with Node/Express backend?

天大地大妈咪最大 提交于 2019-12-05 05:31:40
问题 I have an excel file in a directory on my nodejs server - Path to the file is - ./api/uploads/appsecuritydesign/output/appsecdesign.xlsx On click of a button in my Angular 5 component I am just trying to download the file using FileSaver. Below is my Angular component. Here the template code for the button in Angular that will call the saveFile() function once clicked. <a class="btn btn-primary" (click) = "saveFile()">Download</a> Here is the saveFile() function. saveFile(){ console.log("In

Export contents inside <div> as a .docx File

梦想与她 提交于 2019-12-04 18:01:46
I am having trouble exporting the contents of a div into a .docx file. I am using FileSaver.js which can be found here: https://github.com/eligrey/FileSaver.js/ . My JavaScript Function: function exportNote(){ var blob = new Blob([document.getElementById('editor').innerHTML], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8" }); saveAs(blob, "note.docx"); } I get a download that appears to be a word file but when I open it I get the following error: The Open XML file note.docx cannot be opened because there are problems with the contents or the

How to save following content as PDF in Angularjs using FileSaver.js

前提是你 提交于 2019-12-04 05:24:44
问题 I am unable to save this content as proper PDF using FileSaver.js this is Angular code $http( { url:root.api_root+'/appointments/generatePDF/'+$route‌​Params.id, method:'GE‌​T' }).then(function(r‌​es){ // $log.log(res.data); var blob = new Blob([res.data], { type: 'application/pdf' }); window.open(res.data); // saveAs(blob, 'file.pdf'); }); this is TCPDF Backend code $pdf->Output("php://output", 'F'); echo file_get_contents("php://output"); 回答1: When downloading binary data such as PDF files,