button
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
export const downloadFile = (
|
||||
blob: Blob,
|
||||
fileName: string,
|
||||
extension: 'xlsx' | 'pdf' | 'csv' | 'txt'
|
||||
) => {
|
||||
// Asegurar la extensión correcta
|
||||
const finalFileName = fileName.endsWith(`.${extension}`)
|
||||
? fileName
|
||||
: `${fileName}.${extension}`;
|
||||
|
||||
// Crear una URL para el blob
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
|
||||
// Crear un enlace invisible
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = finalFileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Limpiar la URL creada
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
};
|
||||
Reference in New Issue
Block a user