fix(frontend): add downloadObject function for downloading files from a bucket

This commit is contained in:
Noste
2026-07-03 11:10:33 +02:00
parent 460793632e
commit 430d1a5d68
3 changed files with 29 additions and 18 deletions
+24
View File
@@ -1,3 +1,27 @@
import { objectsApi } from './api';
import { toast } from 'sonner';
/**
* Download an object from a bucket by fetching it as a blob and clicking a
* temporary anchor element. Errors are surfaced by the axios interceptor.
*/
export async function downloadObject(bucket: string, key: string): Promise<void> {
try {
const blob = await objectsApi.get(bucket, key);
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = key.split('/').pop() || 'download';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
toast.success('Download started');
} catch {
// error toast handled by axios interceptor
}
}
/**
* Get the file type based on file extension
*/