strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Problem with uploads

Open piscis opened this issue 9 years ago • 7 comments

Node.js version: v7.10.0 || v6.11.1 npm version: 4.2.0 Strapi version: 1.6.3 Operating system: MacOSx

Hi we currently have a problem testing the upload service of strapi. Everytime we upload a file the server does not respond and the connection closes after some time.

We were able to track it down to the upload service in /api/upload/services/upload.js

Using a valid token with this curl command:

curl \
  -H 'Authorization:Bearer TOKEN_HERE' \
  -F 'img_avatar=@/PATH/TO/FILE/test.png' http://localhost:1337/upload

any help would be much appreciated.

piscis avatar Jul 18 '17 21:07 piscis

@piscis Thanks for reporting this issue. Do you have any logs that you can share with us to try to understand what happens?

Aurelsicoko avatar Jul 19 '17 12:07 Aurelsicoko

sorry there is no log output the upload hangs, but debugging through the code I can see that a ReadableStream (part) was created and then the upload method is called. But the created promise in Line 25 actually never resolves:

https://github.com/strapi/strapi-generate-upload/blob/master/files/api/upload/services/upload.js#L24-L25

piscis avatar Jul 20 '17 11:07 piscis

@piscis did you try to remove the isAuthorized in the routes.json file?

Where exactly the code stop working in the upload function (https://github.com/strapi/strapi-generate-upload/blob/master/files/api/upload/services/upload.js#L24-L25)?

pierreburgy avatar Jul 23 '17 12:07 pierreburgy

@piscis, do you still have the issue?

pierreburgy avatar Jul 28 '17 15:07 pierreburgy

I have the exact same issue on a freshly created app, the function inside Promise never executes. I guess what causes it is incompatibility with new nodejs (v6-v8). It's pretty easy to reproduce, just use strapi 1.6.3 and create a fresh new app with strapi cli then send an upload request.

haiyamicode avatar Aug 30 '17 10:08 haiyamicode

Most likely happens if we use a node version with async/await support, so this is my quick fix: https://gist.github.com/wilonth/2be4e05b82d3f0f5a9bb668f75935955

haiyamicode avatar Aug 30 '17 10:08 haiyamicode

Thanks a lot for your feedback @wilonth!

pierreburgy avatar Aug 30 '17 12:08 pierreburgy