init
This commit is contained in:
29
src/services/file-service/index.ts
Normal file
29
src/services/file-service/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
class FileService {
|
||||
download(file: File, name?: string) {
|
||||
const link = document.createElement('a');
|
||||
const fileUrl = URL.createObjectURL(file);
|
||||
|
||||
link.download = name || file.name;
|
||||
link.href = fileUrl;
|
||||
link.click();
|
||||
|
||||
URL.revokeObjectURL(fileUrl);
|
||||
}
|
||||
|
||||
downloadByDisposition(disposition: string, blob: Blob) {
|
||||
const fileUrl = URL.createObjectURL(blob);
|
||||
const contentDisposition = disposition;
|
||||
const filename = contentDisposition.split('filename=')[1] as string;
|
||||
|
||||
const downloadFileName = filename.slice(1, filename.length - 1);
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.download = downloadFileName;
|
||||
link.href = fileUrl;
|
||||
link.click();
|
||||
|
||||
URL.revokeObjectURL(fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export const file_service = new FileService();
|
||||
Reference in New Issue
Block a user