Content-Disposition fixes + hardening

This commit is contained in:
PJ 2020-02-04 12:52:35 +01:00
parent b2360d5c9e
commit 4833eac81b
2 changed files with 13 additions and 4 deletions

View File

@ -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)

View File

@ -182,8 +182,11 @@ export class Server {
private async handleSkyfilePOST(req: Request, res: Response): Promise<Response> {
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)