Download A File From Storage
utilcn/download-fileFreeComponent
Download a file from a storage provider using a presigned download URL.
Install it
npx shadcn@latest add https://utilcn.dev/r/download-file.jsonSource
1'use client';23import { Download } from 'lucide-react';4import type { PropsWithChildren } from 'react';5import { cn } from '@/lib/utils';6import { useDownloadFile } from '@/registry/default/storage/use-download-file';78type DownloadFileProps = PropsWithChildren<{9 fileKey: string;10 fileName?: string;11 className?: string;12}>;1314export function DownloadFile({15 fileKey,16 fileName,17 children,18 className,19}: DownloadFileProps) {20 const downloadFile = useDownloadFile();2122 const handleDownload = () => {23 downloadFile.mutate(24 { fileKey, fileName },25 {26 onSuccess: (url: string) => {27 console.log('Download initiated:', url);28 },29 onError: (err: Error) => {30 console.error(`Download failed: ${(err as Error).message}`);31 },32 },33 );34 };3536 return (37 <button38 className={cn('flex items-center gap-2', className)}39 disabled={downloadFile.isPending}40 onClick={handleDownload}41 type="button"42 >43 {children || (44 <>45 <Download className="mr-2 h-4 w-4" />46 {downloadFile.isPending ? 'Downloading...' : 'Download'}47 </>48 )}49 </button>50 );51}
What it pulls in
npm packages
Files it writes
More from utilcn
All 17 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Upload A File To Storageupload-file | utilcn | Components | Free | 1 dep · 2 files | |
| Upload Multiple Filesupload-multiple-files | utilcn | Components | Free | no deps · 2 files |
