expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.57k stars 1.06k forks source link

File corruption on zip uploads #597

Open dolftax opened 6 years ago

dolftax commented 6 years ago
[DEVELOPMENT]xxx@xxx-tmp:# unzip e4b18df04249047c0f88a0a141956246 
Archive:  e4b18df04249047c0f88a0a141956246
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
note:  e4b18df04249047c0f88a0a141956246 may be a plain executable, not an archive
unzip:  cannot find zipfile directory in one of e4b18df04249047c0f88a0a141956246 or
        e4b18df04249047c0f88a0a141956246.zip, and cannot find e4b18df04249047c0f88a0a141956246.ZIP, period.

Code:

 // Workspace upload
    let multer = require('multer')({
      dest: `${global.config.tmp.root}`
    })

    app.use('/workspace/upload/util', multer.single('file'), function (req, res, next) {
..
..

Let me know if the above could be caught as an error. If yes, how?

Thanks.

LinusU commented 6 years ago

Are you sure that the file you are uploading is a valid zip-file? How are you uploading the file? Can you less the uploaded file and see if it contains any clues as to what went wrong?

dolftax commented 6 years ago

File: Calculator.zip

less foo.zip

[<FF>d
[<F5>^A^T^@PK^C^D
^@^@^@^@^@<91>k<BB>L^@^@^@^@^@^@^@^@^@^@^@^@&^@^P^@Calculator/app/build/generated/source/UX^L^@<85>q
[*e
[<F5>^A^T^@PK^C^D
^@^@^@^@^@zk<BB>L^@^@^@^@^@^@^@^@^@^@^@^@+^@^P^@Calculator/app/build/generated/source/aidl/UX^L^@<85>q
[<FF>d
[<F5>^A^T^@PK^C^D
^@^@^@^@^@zk<BB>L^@^@^@^@^@^@^@^@^@^@^@^@1^@^P^@Calculator/app/build/generated/source/aidl/debug/UX^L^@<85>q
[<FF>d
[<F5>^A^T^@PK^C^D
^@^@^@^@^@zk<BB>L^@^@^@^@^@^@^@^@^@^@^@^@(^@^P^@Calculator/app/build/generated/source/r/UX^L^@<85>q
[^@e
[<F5>^A^T^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@.^@^P^@Calculator/app/build/generated/source/r/debug/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@6^@^P^@Calculator/app/build/generated/source/r/debug/android/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@>^@^P^@Calculator/app/build/generated/source/r/debug/android/support/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@H^@^P^@Calculator/app/build/generated/source/r/debug/android/support/coreutils/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D^T^@^H^@^H^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@N^@^P^@Calculator/app/build/generated/source/r/debug/android/support/coreutils/R.javaUX^L^@<D4>n
[<82>n
[<F5>^A^T^@<A5><99>Qo<DB>6^P<C7><DF><FD>)<F8>\t<A9>lǎ<83>b^OA^R^O^A<BA><A4>k=^T<C3><94>D<D9>D)Q<A0><A8><A4>n<91>ᆪlY'G<8E><8F>N^P$<84><AD><FB><91><^^<FF>w^T?<BC>cW^?/^^~<FB><E3><F6><FE><F6><CB><D5><E2><F6><86><CD>
<EF>>ݞ1v<F3><C0><EE>^_^V<EC>χ<9B><BB><F9>?g^C<F6>^N~<D9>b%K^V+^<96>쉗<8C>WVg<DC>ʘ+<B5>fK<91>^KíHX<B4>fv%<9C><C1><D2><F0>D   V<A8>j)s<96>^Z<9D><B9>o<98>^Q<A5><AE>L,X<C2>-gҲTWyr<C6><EE><AC>3*W<BA>R ˵e<91>`<99>Nd*7
<D4>^U<87><A7><E0><91>^O<83><82><C7><DF><F9>R0<F8><C0>h<99><9C><95>UQhc<CF>bmDe<A5>*?^N^FE^U)^Y<B3>T<E6>\mG<FD><85><FD>^Z0<F8><D9>~UZ7<FA><CE>^S<DC>Z<B3>}<E8>Ѓ2w^C<86>?<BF><B3><E0><C7>E^Z<8C><82><E0>b<F6><91>d<F2><D9><E8>G<99>^HsUٕ6Ү1<83><FB>1<AE><85><B1>%<B6><8F><FC><EC><E7><C2>ƫ<AF><D6>-ٲ3<8E><F8>^D<CE>BfBW^]<97>$~<98><CF><DB>^UE^D<E1>G<F8><AB>^R<A6>3<91><94>f<FF>ծ^U<EE>w^V<D0><EC><BE>    <B9>\<E1>)φESC<C3><E7>#1^Vi<AD>^H1ƣ8䱕:^O#nB<91>E"      -<8F>v<8B>>^N<E0><87><D6>e<AC><95><A6><C4>5l:<D8>m1<AF>{<DD>v^ۆ<A9>TV<98><A6><EB><F3> ^X^S<96><A7><83><93><B1><9B><C9>r<C3><C3> <C2>:^YY^TJ<84><A0>6<C2>H<AE>B<85>]^O<8C><F3><CB><E3><8C>R<C0>^@^Rn֡^U?l<98><88><94>Wʾ<U+008C>h<BE>M <F6>s<82>oc<9D>^U܆Qe<AD><F3>F^
ESC:^U<F8>      <B1>^D<DD>7<E3>hF0iG<E0>K}^Dip<AA><DC><CB>$l<EF>.<B3><E0>I"<F3>山^R<F6>{?<F7><D5><D1>^R<82>lK<85>ŵF+<F8>o ^Q<F5><C2>^H<81>ַ^A<EA><C0>-<E5>O<81>X^S<82>Z<F7><B1><EA><D0><DB>g^Q<96><B9>Ê$<EC>"i<E2>zG^X<97>Z^Q<8C><B0><BE>^]<98><F3><9B><C8><ED><96>^T<C2><C3><C6>b^^a];<^E^\<B1><F1>٪<A3><90>^N<E6><AB>^Y^H<F6>$^S<BB><C2>,<DF><D5≯<AC>Ŭ<CA><DA>س<BA>@<C8>)A<F9><BB>H<91>H^^<E6><DC>^X<FD><F4>r)<A6>CO<9C>q<EE><EA>^M<B7>
<E9><E8>$T      y<F1><D0>\Ǟ<C4>2<83>2o+<U+242B><97><C6><D5>l^M^\<83><CF>O^G<BB>Y<87><BC><DC>,;fN|<99>UԷ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^^M<A5><E9><^N^BA<90><A2><E3><C0><F0>^N<A5>@G%$^L^B<F5>^S(<F5>^Hc  ^Y<84><80>]<A0>^@pT<82><94><92><A8>H<D3>^\<96> <B7><DF>d<B2>^T<B6>^OwU<EF><F8><EB><FD>t^U^G<C3> <E1>M<C2>1<EE>^Be^F<87>$<CA>_^]<81><B4>s<F1><BF>
<FF><B1>9^L~<CE>3<A9><DC>-<C1>/t<F1><F2>^^]<A2><A0>v<8C><DA>    j^K<D4>N<D9><F3><F1>ٷ^]<87>^Go<81>N<A6>4<F7>@<84>^Z<F4>^@a<FF>&<88><F0><AE><E9>5R{^W<8C>^C<A0><F6>6<88><F0>6<E9>^@<A3><B9>^O:<FE><EE><A8>^SESC<F3>
<CD>՞<8B>^O8#^M<83><C9>x<F4><BE>m<8F>Q;Eq0k۳^@<B5><87>~<F1><E1>Z<E1><F6>R3l.^Y<DF>^D<D8><DD>Ry<C5><C7>^KLsI<E6>^UESC5e;^K<AF>X<D8>^Y6<DD>zE<C1><CE>z7<F7>I#'σ<FF>^APK^G^H<84><A8>Ad<8E>^E^@^@<F2>^^^@^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@A^@^P^@Calculator/app/build/generated/source/r/debug/android/support/v7/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D
^@^@^@^@^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@K^@^P^@Calculator/app/build/generated/source/r/debug/android/support/v7/appcompat/UX^L^@<85>q
[<82>n
[<F5>^A^T^@PK^C^D^T^@^H^@^H^@^Mq<BB>L^@^@^@^@^@^@^@^@^@^@^@^@Q^@^P^@Calculator/app/build/generated/source/r/debug/android/support/v7/appcompat/R.javaUX^L^@<85>n
[<82>n
[<F5>^A^T^@<AD>}ks<DB><C8>r<F6><F7><FD>^U<FA><9C>J6<82>$<92>b<A5><DE>^O<B2><BC>^<BB><E2>۱<B4><EB>z+<95>b<E1>2$^Q<83>^@^N^@<DA><D6>I<9D><FF><9E><B9>^A<E8><B9>^@|<86><DC>T<92><85>%<F5><83><C1>LwOO<DF><E6><DF><FF>
<E5><EA><E1><8F><E7>O<FF><F6><FB>o^_^?<FB><F2><F0><FC><DB><EB><AB>7<EF><DE><FF><F6><EB><D5><D5><EB>OW^_?=_}<F8><F4><FA>ݛ<FF><FF><EB>/W<FF><C2><FF><F7><EA>y<9F><B7>Wi^Q<B7><ED>Տ<B8><BD><8A><8F>]u<88><BB><<8D><8B>
<E2><E5>j<C7>J<D6><C4>^]ˮ<92><97><AB>n<CF>^D<C1><AE><89><B3><82>]<D5><C5>q<97><97>Wۦ:<88><DF>\5<AC><AD><8E>Mʮ<B2><B8><8B><AF><F2><EE>j[^]<CB><EC><U+05EB>w<9D> j<F7>ձȮʪ<BB>J<D8>ա<CA><F2>m<AE>P<F7>1<FF>+<FE>'<FF>
<FE>K^]<A7><DF><E2>^]<BB><E2>?h<AA><<FB><B5>=<D6>u<D5>t<BF>~_<FD>^Z<D7>uZ^]<EA><B8><FB><8F>_~<A9><8F>I<91><A7>Wۼ<8C>^K=<F0>/W<FF><FB><CB>^U<FF>^_<FD><AB><B6>^S^_`<FC>E\<E6>^G<FD>GS^?<98><97><DD>U<9C><A4><9B>m<9C>
<B1>^M<FF><B2><FF>wu<FD>s<B5><BD><8E><AE><F9><FF><FC>^GNY^];J^Za<A4><BB><A6><FA>ѿy#<E6>t<93>T^]_     
u<83>A<D5>U}<AC>7<AC><EC>XC<A9>o<83><A8>^?<E6><C6>W<DC>a<C4><ED><BE><C9><CB>o<C3><L}<C8>^BD+r5^_.<C2>2^P<A1><AB>jJ<BE>
!^W^_<E2><8E><E0>>^T<C2>^Z<C2>^Z<A3>着<E8>r<CF>rƁ<F4>ւ&<8A><FC><9F><A7>Ħ<EB>^ZDl<D2>.<AF><CA>Wq<F3>:<FF>οw^X<E8>^M(;=<F9><BB><8E>^]^q-<C0><A5><81><EB>^N<8A><82><88>Q<8F><F2>Y<B0><F0><F3><9E>^]^XE@<A4><A7>Gx<CA>
<FF>a<D0>"<B2>3<D0><D6>E<DE>=u/<85><81><80>^HЀ`^S#<F2><D2>^S?lj^O^B^Q^X^B<E1><D0>#^RC<E8><9F><D9>Ow^N^P<91>^Y0<EC><E5>C<E4><A5>'<FE><9A>g;<D6>9^P<88><C8>(<88>#<97><F6><D2>^Y^?<82>ҿn<AA><FA>u<F5><C3>EHQ<84><F7><F1>
^K<D9>G^Di<86><92>~`<E5>QL<FF>C]<B3><B8><89><CB><D4>^X^A^K<85>y<AC><8A>ʐ<E7>-<8C>Pe<CC>+<CC>^Q<AC>^R^D<C4>cQ<B5>̿"^Q<AC>^U^F<A0><D7>M<FC>#NL^TX3H<94><AA>~<F1><81><C0>*B<82>^\;^_^F<AC>$^Dƛ<BC><CC>| <B0><B2>^P <9F>
<E3><B6><F3><CE>       <AC>/$<8A>P<B8>_<F9>x<AA>^_<CE>^R<C1><8A>C^@=<B1><82><A5><DD>CQ<F8><86>^D<AB>^O<89><B4><8F>ESC<EF><87><C1>zD<A2>^H]<EE><E7>aX<99>H^\{V`U"<A8><BF><B2>䉋r<BA><F7>}^O<AC>R>}g<U+0376><A8>~L<88>
^R<AC>_z^\<A1> ^\^TX<BD>|n*i)<J3<83>
LinusU commented 6 years ago

Is foo.zip here the file after it has been uploaded to multer?

dolftax commented 6 years ago

@LinusU Yes.

LinusU commented 6 years ago

How are you uploading it?

dolftax commented 6 years ago

Using this module in Angular.js - https://github.com/danialfarid/ng-file-upload

 Upload.upload({
              url: $rootScope.baseUrl + 'upload/util',
              data: {file: file}
            }).then(function (resp) {
              console.log('Uploaded workspace')
            })
})
LinusU commented 6 years ago

Could you try uploading it using a simple <form enctype="multipart/form-data" ...> and see if that works?

dolftax commented 6 years ago

@LinusU Same result. Multer 1.3.0

GNSubrahmanyam commented 5 years ago

@LinusU Any updates? Still this issue is happening :-(

zeroum commented 5 years ago

I came here looking for the same problem, but in my particular case the issue was elsewhere:

My Express+Multer NodeJS program is hosted in AWS Lambda, and the request is being delivered through their API Gateway service. That Gateway was the one corrupting the binaries.

Since I use the Serverless Framework tooling, I fixed it by using a plugin(serverless-apigw-binary) to config the correct settings in the service for me.

pannnnn commented 5 years ago

I am having the same issue but the corrupted file is a jpg file. And after a few trials, I think the cause is that inside the callback function, i.e., function(req, res, next) { ...blabla }, it calls res.json/send/end before the image is fully received and saved to disk.

HarshithaKP commented 4 years ago

@jaipradeesh Is this still an issue for you ?. If yes, can you check with the 'Content-Type' which you have specified.

GNSubrahmanyam commented 4 years ago

@jaipradeesh Is this still an issue for you ?. If yes, can you check with the 'Content-Type' which you have specified.

Yes

ajouve commented 4 years ago

I have a similar issue there https://github.com/expressjs/multer/issues/879