Upload function and state
function ImageUploader() {
const { upload, isSupported, isUploading, error, fileId } = useFileUpload();
if (!isSupported) {
return <div>File upload not supported on this platform</div>;
}
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
const result = await upload(file);
console.log("Uploaded:", result?.fileId);
}
};
return (
<div>
<input type="file" accept="image/*" onChange={handleFileChange} />
{isUploading && <span>Uploading...</span>}
{error && <span>Error: {error.message}</span>}
{fileId && <span>Uploaded: {fileId}</span>}
</div>
);
}
Hook for uploading files (ChatGPT only)
Provides a function to upload files and tracks upload state. On unsupported platforms, isSupported will be false.
Supported file types: PNG, JPEG, WebP images