Skip to content

Commit 8ce6f8f

Browse files
committed
prevent file upload if no file selected
1 parent 42e1da4 commit 8ce6f8f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

app/src/client/app/FileUploadPage.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ export default function FileUploadPage() {
3636
}, [fileToDownload]);
3737

3838
const handleUpload = async (e: FormEvent<HTMLFormElement>) => {
39-
e.preventDefault();
40-
const formData = new FormData(e.target as HTMLFormElement);
41-
const file = formData.get('file-upload') as File;
42-
if (!file) {
43-
console.error('No file selected');
44-
return;
45-
}
39+
try {
40+
e.preventDefault();
41+
const formData = new FormData(e.target as HTMLFormElement);
42+
const file = formData.get('file-upload') as File;
43+
if (!file || !file.name || !file.type) {
44+
throw new Error('No file selected');
45+
}
4646

47-
const fileType = file.type;
48-
const name = file.name;
47+
const fileType = file.type;
48+
const name = file.name;
4949

50-
try {
5150
const { uploadUrl } = await createFile({ fileType, name });
5251
if (!uploadUrl) {
5352
throw new Error('Failed to get upload URL');

0 commit comments

Comments
 (0)