Skip to content

Commit

Permalink
fix: proxy stream workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
smarroufin committed Feb 1, 2024
1 parent c15adce commit d1f7bcd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion _nuxthub/server/api/_hub/blob/[...pathname].put.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
async function streamToArrayBuffer(stream: ReadableStream, streamSize: number) {
const result = new Uint8Array(streamSize)
let bytesRead = 0
const reader = stream.getReader()
while (true) {
const { done, value } = await reader.read()
if (done) {
break
}
result.set(value, bytesRead)
bytesRead += value.length
}
return result
}

export default eventHandler(async (event) => {
const { pathname } = await getValidatedRouterParams(event, z.object({
pathname: z.string().min(1)
Expand All @@ -11,7 +26,8 @@ export default eventHandler(async (event) => {
if (!options.contentType) { options.contentType = contentType }
if (!options.contentLength) { options.contentLength = contentLength }

const body = getRequestWebStream(event)!
const stream = getRequestWebStream(event)!
const body = await streamToArrayBuffer(stream, contentLength)

return useBlob().put(pathname, body, options)
})

0 comments on commit d1f7bcd

Please sign in to comment.