@@ -156,12 +156,6 @@ class LDP {
156156 }
157157 // const { url: putUrl } = await this.resourceMapper.mapFileToUrl({ path: resourceUrl, hostname })
158158
159- // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
160- // for JSON bodies. So, the stream needs to be reset
161- if ( contentType && contentType . includes ( 'application/json' ) ) {
162- stream = intoStream ( JSON . stringify ( stream . body ) )
163- }
164-
165159 await ldp . put ( resourceUrl , stream , contentType )
166160 return URL . parse ( originalUrl ) . path
167161 }
@@ -240,6 +234,11 @@ class LDP {
240234
241235 // Directory created, now write the file
242236 return withLock ( path , { mustExist : false } , ( ) => new Promise ( ( resolve , reject ) => {
237+ // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
238+ // for JSON bodies. So, the stream needs to be reset
239+ if ( contentType . includes ( 'application/json' ) ) {
240+ stream = intoStream ( JSON . stringify ( stream . body ) )
241+ }
243242 const file = stream . pipe ( fs . createWriteStream ( path ) )
244243 file . on ( 'error' , function ( ) {
245244 reject ( error ( 500 , 'Error writing data' ) )
0 commit comments