fix(mobile): support file downloads and image previews

This commit is contained in:
Bohdan Triapitsyn
2026-08-13 23:44:36 +03:00
parent 0da89f3f88
commit 55fcd5092e
3 changed files with 48 additions and 53 deletions
+11 -1
View File
@@ -285,10 +285,20 @@ export const createWebFilesAPI = ({ getDirectory }: WebFilesAPIOptions): FilesAP
}
const blob = await response.blob();
const filename = target.split('/').pop() || 'file';
const capacitor = (window as typeof window & {
Capacitor?: { isNativePlatform?: () => boolean };
}).Capacitor;
const file = new File([blob], filename, { type: blob.type || 'application/octet-stream' });
if (capacitor?.isNativePlatform?.() === true && navigator.canShare?.({ files: [file] })) {
await navigator.share({ files: [file] });
return;
}
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = target.split('/').pop() || 'file';
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);