fix: download url

This commit is contained in:
BennyKok
2023-12-29 16:23:45 +08:00
parent d54ed35755
commit 62f8ba2c70
4 changed files with 45 additions and 33 deletions
+27
View File
@@ -0,0 +1,27 @@
"use client";
import { Button } from "@/components/ui/button";
import { Download } from "lucide-react";
export function DownloadButton(props: { href: string; filename: string }) {
return (
<Button
className="gap-2"
onClick={async () => {
const url = props.href;
console.log(url);
const a = document.createElement("a");
a.href = url;
a.download = props.filename;
a.target = "_blank"; // Add this line
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}}
>
Download <Download size={14} />
</Button>
);
}