File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
_nuxthub/server/api/_hub/blob Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change
1
+ async function streamToArrayBuffer ( stream : ReadableStream , streamSize : number ) {
2
+ const result = new Uint8Array ( streamSize )
3
+ let bytesRead = 0
4
+ const reader = stream . getReader ( )
5
+ while ( true ) {
6
+ const { done, value } = await reader . read ( )
7
+ if ( done ) {
8
+ break
9
+ }
10
+ result . set ( value , bytesRead )
11
+ bytesRead += value . length
12
+ }
13
+ return result
14
+ }
15
+
1
16
export default eventHandler ( async ( event ) => {
2
17
const { pathname } = await getValidatedRouterParams ( event , z . object ( {
3
18
pathname : z . string ( ) . min ( 1 )
@@ -11,7 +26,8 @@ export default eventHandler(async (event) => {
11
26
if ( ! options . contentType ) { options . contentType = contentType }
12
27
if ( ! options . contentLength ) { options . contentLength = contentLength }
13
28
14
- const body = getRequestWebStream ( event ) !
29
+ const stream = getRequestWebStream ( event ) !
30
+ const body = await streamToArrayBuffer ( stream , contentLength )
15
31
16
32
return useBlob ( ) . put ( pathname , body , options )
17
33
} )
You can’t perform that action at this time.
0 commit comments