From 4833eac81b2af402b1a2201106e063c4544a1970 Mon Sep 17 00:00:00 2001 From: PJ Date: Tue, 4 Feb 2020 12:52:35 +0100 Subject: [PATCH] Content-Disposition fixes + hardening --- .../siaviewnode-client/src/components/Dropzone.tsx | 10 ++++++++-- packages/siaviewnode-server/src/main.ts | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/siaviewnode-client/src/components/Dropzone.tsx b/packages/siaviewnode-client/src/components/Dropzone.tsx index ee66856c..f72ce89b 100644 --- a/packages/siaviewnode-client/src/components/Dropzone.tsx +++ b/packages/siaviewnode-client/src/components/Dropzone.tsx @@ -22,8 +22,14 @@ function MyDropzone() { const onDrop = useCallback( acceptedFiles => { setLoading(true) - const file = R.head(acceptedFiles) - const url = API_ENDPOINT + "/skyfile" + const file = acceptedFiles[0] + if (!file) { + setError("An unexpected error occured. Check console for details.") + setLoading(false) + return + } + + const url = `${API_ENDPOINT}/skyfile?filename=${file.name}` const fd = new FormData() fd.append("file", file) diff --git a/packages/siaviewnode-server/src/main.ts b/packages/siaviewnode-server/src/main.ts index 8fb6e113..2ef6a1c7 100644 --- a/packages/siaviewnode-server/src/main.ts +++ b/packages/siaviewnode-server/src/main.ts @@ -182,8 +182,11 @@ export class Server { private async handleSkyfilePOST(req: Request, res: Response): Promise { const file = selectFile(req) as UploadedFile - const uid = shortid.generate() + if (!file) { + res.status(400).send({ error: "Missing file" }) + } + const uid = shortid.generate() this.logger.info(`POST skyfile w/name ${file.name} and uid ${uid}`) try { @@ -192,7 +195,7 @@ export class Server { file.data, { maxContentLength: MAX_UPLOAD_FILESIZE, - params: { name: file.name } + params: { filename: file.name } } ) return res.send(data)