Skip to content

Commit 09a580d

Browse files
committed
chore: improve multipart files parsing
1 parent 7ceee8f commit 09a580d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

_nuxthub/server/utils/bucket.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,10 @@ function toArrayBuffer (buffer: Buffer) {
147147
}
148148
return arrayBuffer
149149
}
150+
151+
export async function readFiles (event: H3Event<EventHandlerRequest>) {
152+
const files = (await readMultipartFormData(event) || [])
153+
154+
// Filter only files
155+
return files.filter((file) => Boolean(file.filename))
156+
}

server/api/storage/index.put.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
export default eventHandler(async (event) => {
22
await requireUserSession(event)
33

4-
let files = (await readMultipartFormData(event) || [])
5-
6-
// Filter only files
7-
files = files.filter((file) => Boolean(file.filename))
4+
const files = await readFiles(event)
85
if (!files) {
96
throw createError({ statusCode: 400, message: 'Missing files' })
107
}

0 commit comments

Comments
 (0)