Skip to content

Instantly share code, notes, and snippets.

@alexalannunes
Created February 13, 2020 12:28
Show Gist options
  • Save alexalannunes/ae536871bb3cfaed1a2149036356bcda to your computer and use it in GitHub Desktop.
Save alexalannunes/ae536871bb3cfaed1a2149036356bcda to your computer and use it in GitHub Desktop.
/**
* download de um arquivo
*
* @param {Blob} file
* @example
* ...
* exec(response.data)
* ...
*/
function exec(file, type = "text/csv") {
var blob = new Blob([file], { type });
var filename =
moment().format("Y_MM_D") + "_waves_" + Date.now().toString(16) + ".csv";
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment