Can force file download

This commit is contained in:
2025-05-01 19:09:43 +02:00
parent 40cf0c16df
commit cfbc003737
3 changed files with 51 additions and 26 deletions

View File

@ -41,7 +41,10 @@ export class FileApi {
/**
* Get a file download URL
*/
static DownloadURL(file: UploadedFile): string {
return APIClient.backendURL() + `/file/${file.id}/download`;
static DownloadURL(file: UploadedFile, forceDownload = false): string {
return (
APIClient.backendURL() +
`/file/${file.id}/download${forceDownload ? "?download=true" : ""}`
);
}
}

View File

@ -25,6 +25,7 @@ export function FileViewerDialog(p: {
fileName={p.file.file_name}
fileSize={p.file.file_size}
url={FileApi.DownloadURL(p.file)}
downloadUrl={FileApi.DownloadURL(p.file, true)}
mimetype={p.file.mime_type}
/>
<DialogActions>
@ -38,6 +39,7 @@ interface ViewerProps {
fileName: string;
fileSize: number;
url: string;
downloadUrl: string;
mimetype: string;
}
@ -65,7 +67,7 @@ function DefaultViewer(p: ViewerProps): React.ReactElement {
<Typography variant="caption" gutterBottom>
{filesize(p.fileSize)}
</Typography>
<a href={p.url} target="_blank" referrerPolicy="no-referrer">
<a href={p.downloadUrl} target="_blank" referrerPolicy="no-referrer">
<Button variant="outlined">Download</Button>
</a>
</Paper>