A React component for managing files in Vercel Blob storage.
npm install @hcapp01/blob-manager
import { useRef, useState } from 'react'
import { FileManager, FileManagerRef } from '@hcapp01/vercel-blob-file-manager'
import { BlobFile } from '@hcapp01/vercel-blob-file-manager'
function App() {
const [selectedFile, setSelectedFile] = useState<BlobFile | null>(null)
const [fileContent, setFileContent] = useState('')
const [isLoading, setIsLoading] = useState(false)
const [isConnected, setIsConnected] = useState(false)
const fileManagerRef = useRef<FileManagerRef>(null)
const handleFileSelect = async (file: BlobFile) => {
setSelectedFile(file)
if (fileManagerRef.current) {
try {
const content = await fileManagerRef.current.handleReadFile(file)
setFileContent(content)
} catch (error) {
console.error('Failed to read file:', error)
}
}
}
const handleSave = async (content: string) => {
if (!selectedFile || !fileManagerRef.current) return
await fileManagerRef.current.handleSaveFile(selectedFile, content)
setFileContent(content)
}
return (
<div>
{isConnected && <Uploader fileManagerRef={fileManagerRef} />}
<FileManager
ref={fileManagerRef}
onFileSelect={handleFileSelect}
isLoading={isLoading}
setIsLoading={setIsLoading}
config={{ confirmDelete: true }}
onConnectionChange={setIsConnected}
/>
{selectedFile && (
<FileEditor
content={fileContent}
onSave={handleSave}
isLoading={isLoading}
/>
)}
</div>
)
}
ref
: Reference to access FileManager methodsonFileSelect
: Callback when a file is selected, receives file objectisLoading
: Loading state for file operationssetIsLoading
: Function to update loading stateconfig
: Configuration objectconfirmDelete
: Show confirmation dialog before deleting files (default: false)
onConnectionChange
: Callback when Blob storage connection status changesclassName
: Optional CSS class name
handleReadFile
: Read content of a filehandleSaveFile
: Create new or update existing file with contentisConnected
: Boolean indicating if connected to Blob storage
fileManagerRef
: Reference to FileManager component
content
: Current file contentonSave
: Callback when saving changesisLoading
: Loading state indicator