@@ -28,7 +28,7 @@ function suggestUrl(short: string, baseUrl: string, filename?: string, contentAs
2828type ParsedMultipartPart = {
2929 filename ?: string
3030 content : ReadableStream | ArrayBuffer
31- contentAsString ?: string
31+ contentAsString : ( ) => string
3232 contentLength : number
3333}
3434
@@ -43,13 +43,14 @@ async function multipartToMap(req: Request, sizeLimit: number): Promise<Map<stri
4343 filename : part . filename ,
4444 content : arrayBuffer ,
4545 contentLength : arrayBuffer . byteLength ,
46+ contentAsString : ( ) => decode ( arrayBuffer ) ,
4647 } )
4748 } else {
4849 const arrayBuffer = await part . arrayBuffer ( )
4950 partsMap . set ( part . name , {
5051 filename : part . filename ,
5152 content : arrayBuffer ,
52- contentAsString : decode ( arrayBuffer ) ,
53+ contentAsString : ( ) => decode ( arrayBuffer ) ,
5354 contentLength : arrayBuffer . byteLength ,
5455 } )
5556 }
@@ -112,17 +113,14 @@ export async function handlePostOrPut(
112113 throw new WorkerError ( 400 , "cannot find content in formdata" )
113114 }
114115 const { filename, content, contentAsString, contentLength } = parts . get ( "c" ) !
115- const nameFromForm = parts . get ( "n" ) ?. contentAsString
116+ const nameFromForm = parts . get ( "n" ) ?. contentAsString ( )
116117 const isPrivate = parts . has ( "p" )
117- const passwdFromForm = parts . get ( "s" ) ?. contentAsString
118- const expireFromForm : string | undefined = parts . get ( "e" ) ?. contentAsString
119- const encryptionScheme : string | undefined = parts . get ( "encryption-scheme" ) ?. contentAsString
118+ const passwdFromForm = parts . get ( "s" ) ?. contentAsString ( )
119+ const expireFromForm : string | undefined = parts . get ( "e" ) ?. contentAsString ( )
120+ const encryptionScheme : string | undefined = parts . get ( "encryption-scheme" ) ?. contentAsString ( )
120121 const expire = expireFromForm ? expireFromForm : env . DEFAULT_EXPIRATION
121122
122- if ( isMPUComplete && contentAsString === undefined ) {
123- throw new WorkerError ( 400 , `field c in formdata mistakenly carries a filename for MPU complete` )
124- }
125- const uploadedParts = isMPUComplete ? ( JSON . parse ( contentAsString ! ) as R2UploadedPart [ ] ) : undefined
123+ const uploadedParts = isMPUComplete ? ( JSON . parse ( contentAsString ( ) ) as R2UploadedPart [ ] ) : undefined
126124
127125 // parse expiration
128126 let expirationSeconds = parseExpiration ( expire )
@@ -212,7 +210,7 @@ export async function handlePostOrPut(
212210 return makeResponse (
213211 {
214212 url : accessUrl ( pasteName ) ,
215- suggestedUrl : suggestUrl ( pasteName , env . DEPLOY_URL , filename , contentAsString ) ,
213+ suggestedUrl : suggestUrl ( pasteName , env . DEPLOY_URL , filename , contentAsString ( ) ) ,
216214 manageUrl : manageUrl ( pasteName , newPasswd ) ,
217215 expirationSeconds,
218216 expireAt : new Date ( now . getTime ( ) + 1000 * expirationSeconds ) . toISOString ( ) ,
@@ -252,7 +250,7 @@ export async function handlePostOrPut(
252250 return makeResponse (
253251 {
254252 url : accessUrl ( pasteName ) ,
255- suggestedUrl : suggestUrl ( pasteName , env . DEPLOY_URL , filename , contentAsString ) ,
253+ suggestedUrl : suggestUrl ( pasteName , env . DEPLOY_URL , filename , contentAsString ( ) ) ,
256254 manageUrl : manageUrl ( pasteName , password ) ,
257255 expirationSeconds,
258256 expireAt : new Date ( now . getTime ( ) + 1000 * expirationSeconds ) . toISOString ( ) ,
0 commit comments