How to use file-saver - 10 common examples

To help you get started, we’ve selected a few file-saver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chrishamm / DuetWebControl / src / components / lists / BaseFileList.vue View on Github external
async download(item) {
			try {
				const filename = (item && item.name) ? item.name : this.innerValue[0].name;
				const blob = await this.machineDownload({ filename: Path.combine(this.innerDirectory, filename), type: 'blob' });
				saveAs(blob, filename);
			} catch (e) {
				if (!(e instanceof DisconnectedError) && !(e instanceof OperationCancelledError)) {
					// should be handled before we get here
					console.warn(e);
				}
			}
		},
		async edit(item) {
github nteract / nteract / packages / epics / src / contents.ts View on Github external
export function downloadString(
  fileContents: string,
  filepath: string,
  contentType: string
): void {
  const filename = filepath.split("/").pop();
  const blob = new Blob([fileContents], { type: contentType });
  // NOTE: There is no callback for this, we have to rely on the browser
  //       to do this well, so we assume it worked
  FileSaver.saveAs(blob, filename);
}
github ProtonMail / WebClient / src / app / attachments / services / attachmentDownloader.js View on Github external
const downloadFile = (blob, name, el) => {
        try {
            if (hasFileSaverSupported) {
                return saveAs(blob, name);
            }

            // Bad blob support, make a data URI, don't click it
            const reader = new FileReader();
            reader.onloadend = () => {
                el.href = reader.result;
            };

            reader.readAsDataURL(blob);
        } catch (error) {
            console.error(error);
        }
    };
github openpowerquality / opq / view / app / imports / ui / pages / eventDetails / eventDetails.js View on Github external
const calibratedSample = sample / constant;

          // return [timestamp, calibratedSample];
          return calibratedSample;
        });

        // eslint-disable-next-line max-len
        const eventPicked = _.pick(boxEvent, 'event_id', 'box_id', 'event_start_timestamp_ms', 'event_end_timestamp_ms', 'waveformCalibrated');
        if (export_type === 'json') {
          const json = JSON.stringify(eventPicked, null, 2);
          const blob = new Blob([json], { type: 'application/json; charset=utf-8' }); // eslint-disable-line no-undef
          Filesaver.saveAs(blob, `event-${eventPicked.event_id}-device-${eventPicked.box_id}`);
        } else if (export_type === 'csv') {
          const csv = Papaparse.unparse([eventPicked]);
          const blob = new Blob([csv], { type: 'text/csv; charset=utf-8' }); // eslint-disable-line no-undef
          Filesaver.saveAs(blob, `event-${eventPicked.event_id}-device-${eventPicked.box_id}`);
        }
      }
    }
    /* eslint-disable camelcase, no-console, no-shadow */
  },
});
github ParasolJS / parasol-es / src / api / exportData.js View on Github external
} else if (selection == 'marked') {
      d = config.marked;
    } else if (selection == 'both') {
      d = config.selections();
    } else {
      throw "Please specify one of {'brushed', 'marked', 'both'}";
    }

    if (d.length > 0) {
      // format data as csv
      // NOTE: include assigned data id number?
      const csv = csvFormat(d, config.vars);

      // create url and download
      const file = new Blob([csv], { type: 'text/csv' });
      saveAs(file, filename);
    } else {
      throw 'Error: No data selected.';
    }
    return this;
  };
github gammafp / atlas-packer-phaser / src / app / pages / animator / animator / animator.component.ts View on Github external
.then(function (content) {
                saveAs(content, `PP3.zip`);
            });
        //     // End generate zip
github gammafp / atlas-packer-phaser / src / app / pages / editor / editor / editor.component.ts View on Github external
.then(function (content) {
                    saveAs(content, `PP3.zip`);
                });
            // End generate zip
github fairDataSociety / fds.js / lib / models / Message.js View on Github external
    return this.getFile(decryptProgressCallback = console.log, downloadProgressCallback = console.log).then(file => saveAs(file));  
  }
github TreeHacks / root / src / store / admin / actions.ts View on Github external
let results = (sheets ? unwind(e.results, "categories"): e.results).map(item => {
      let newItem = {};
      for (let column of columns) {
        let value = "";
        if (typeof column.accessor === "function") {
          value = column.accessor(item);
        }
        else {
          value = get(item, column.accessor);
        }
        newItem[column.Header] = value;
      }
      return newItem;
    }
    );
    saveAs(new Blob([Papa.unparse(results)]), `treehacks-hacks-${Date.now()}.csv`);
    dispatch(setExportedApplications(results));
    dispatch(loadingEnd());
  }).catch(e => {
    console.error(e);
github ng-alain / delon / packages / abc / down-file / down-file.spec.ts View on Github external
it('should be using header filename when repseon has [filename]', () => {
      let fn: string;
      const filename = 'newfile.docx';
      spyOn(fs.default, 'saveAs').and.callFake((_body: {}, fileName: string) => (fn = fileName));
      context.fileName = null;
      fixture.detectChanges();
      (dl.query(By.css('#down-docx')).nativeElement as HTMLButtonElement).click();
      const ret = httpBed.expectOne(req => req.url.startsWith('/')) as TestRequest;
      ret.flush(genFile(), {
        headers: new HttpHeaders({ filename }),
      });
      expect(fn!).toBe(filename);
    });

file-saver

An HTML5 saveAs() FileSaver implementation

MIT
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis