This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-31
lines changed
Expand file tree Collapse file tree 2 files changed +25
-31
lines changed Original file line number Diff line number Diff line change 5959 "err-code" : " ^2.0.0" ,
6060 "hamt-sharding" : " ~0.0.2" ,
6161 "interface-datastore" : " ~0.7.0" ,
62- "ipfs-multipart" : " ~0.1 .0" ,
62+ "ipfs-multipart" : " ~0.2 .0" ,
6363 "ipfs-unixfs" : " ~0.1.16" ,
6464 "ipfs-unixfs-exporter" : " ~0.38.0" ,
6565 "ipfs-unixfs-importer" : " ~0.40.0" ,
Original file line number Diff line number Diff line change @@ -28,39 +28,33 @@ const mfsWrite = {
2828 shardSplitThreshold
2929 } = request . query
3030
31- const fileStream = await new Promise ( ( resolve , reject ) => {
32- const parser = multipart . reqParser ( request . payload )
33- let fileStream
31+ let files = 0
3432
35- parser . on ( 'file' , ( _ , stream ) => {
36- if ( fileStream ) {
37- return reject ( Boom . badRequest ( 'Please only send one file' ) )
38- }
39-
40- fileStream = stream
41- resolve ( fileStream )
42- } )
33+ for await ( const entry of multipart ( request ) ) {
34+ if ( entry . type === 'file' ) {
35+ files ++
4336
44- parser . on ( 'error' , ( error ) => {
45- reject ( error )
46- } )
47- } )
37+ if ( files > 1 ) {
38+ throw Boom . badRequest ( 'Please only send one file' )
39+ }
4840
49- await ipfs . files . write ( arg , fileStream , {
50- offset,
51- length,
52- create,
53- truncate,
54- rawLeaves,
55- cidVersion,
56- hashAlg,
57- format,
58- parents,
59- progress,
60- strategy,
61- flush,
62- shardSplitThreshold
63- } )
41+ await ipfs . files . write ( arg , entry . content , {
42+ offset,
43+ length,
44+ create,
45+ truncate,
46+ rawLeaves,
47+ cidVersion,
48+ hashAlg,
49+ format,
50+ parents,
51+ progress,
52+ strategy,
53+ flush,
54+ shardSplitThreshold
55+ } )
56+ }
57+ }
6458
6559 return h . response ( )
6660 } ,
You can’t perform that action at this time.
0 commit comments