Skip to content

Commit

Permalink
Adds image uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Gupta committed Nov 8, 2023
1 parent f0f788e commit cfbd6af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 27 additions & 2 deletions examples/web/src/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ const ImageLoader = () => {
const [path, setPath] = useState<string>('');
const { controller } = useCurrentController();

const loadImage = async (path: string) => {
const loadImage = async (path: string) => {
controller && controller.addImage(path);
}
}

const handleUpload = (e: any) => {
const fileReader = new FileReader();
const name = e.target.accept.includes('image') ? 'images' : 'videos';

fileReader.readAsDataURL(e.target.files[0]);
fileReader.onload = (e) => {
const path = e.target?.result as string;
setPath(path);
loadImage(path);
};
}

return (
<Stack direction="row" spacing={2}>
Expand All @@ -20,6 +32,19 @@ const ImageLoader = () => {
value={path}
onChange={(e) => setPath(e.target.value)} />
<Button onClick={() => loadImage(path || 'https://i.imgur.com/XbLP6ux.png')}>Load Image</Button>
<input
accept="image/*"
style={{ display: 'none' }}
id="raised-button-file"
multiple
type="file"
onChange={handleUpload}
/>
<label htmlFor="raised-button-file">
<Button component="span" style={{ height: "100%" }}>
Upload
</Button>
</label>
</Stack>
)
}
Expand Down
5 changes: 5 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rewrites": [
{"source": "/(.*)", "destination": "/"}
]
}

0 comments on commit cfbd6af

Please sign in to comment.