server icon indicating copy to clipboard operation
server copied to clipboard

Can't upload large images (up to +1MB)

Open stilic opened this issue 5 years ago • 7 comments

When I try to upload a image with a +1MB as guild- picture, I get this error in server's logs:

1|fosscord  | PayloadTooLargeError: request entity too large
1|fosscord  |     at readStream (/home/admin/fosscord-server/cdn/node_modules/raw-body/index.js:155:17)
1|fosscord  |     at getRawBody (/home/admin/fosscord-server/cdn/node_modules/raw-body/index.js:108:12)
1|fosscord  |     at read (/home/admin/fosscord-server/cdn/node_modules/body-parser/lib/read.js:77:3)
1|fosscord  |     at jsonParser (/home/admin/fosscord-server/cdn/node_modules/body-parser/lib/types/json.js:135:5)
1|fosscord  |     at Layer.handle [as handle_request] (/home/admin/fosscord-server/bundle/node_modules/express/lib/router/layer.js:95:5)
1|fosscord  |     at trim_prefix (/home/admin/fosscord-server/bundle/node_modules/express/lib/router/index.js:317:13)
1|fosscord  |     at /home/admin/fosscord-server/bundle/node_modules/express/lib/router/index.js:284:7
1|fosscord  |     at Function.process_params (/home/admin/fosscord-server/bundle/node_modules/express/lib/router/index.js:335:12)
1|fosscord  |     at next (/home/admin/fosscord-server/bundle/node_modules/express/lib/router/index.js:275:10)
1|fosscord  |     at /home/admin/fosscord-server/cdn/node_modules/lambert-server/dist/Server.js:105:17 {
1|fosscord  |   expected: 1049647,
1|fosscord  |   length: 1049647,
1|fosscord  |   limit: 102400,
1|fosscord  |   type: 'entity.too.large'
1|fosscord  | }

stilic avatar Sep 03 '21 20:09 stilic

Same here,

PayloadTooLargeError: request entity too large
    at readStream (C:\Users\Patten\fosscord\server\fosscord-server\cdn\node_modules\raw-body\index.js:155:17)
    at getRawBody (C:\Users\Patten\fosscord\server\fosscord-server\cdn\node_modules\raw-body\index.js:108:12)
    at read (C:\Users\Patten\fosscord\server\fosscord-server\cdn\node_modules\body-parser\lib\read.js:77:3)
    at jsonParser (C:\Users\Patten\fosscord\server\fosscord-server\cdn\node_modules\body-parser\lib\types\json.js:135:5)
    at Layer.handle [as handle_request] (C:\Users\Patten\fosscord\server\fosscord-server\bundle\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Patten\fosscord\server\fosscord-server\bundle\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Patten\fosscord\server\fosscord-server\bundle\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Patten\fosscord\server\fosscord-server\bundle\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Patten\fosscord\server\fosscord-server\bundle\node_modules\express\lib\router\index.js:275:10)
    at C:\Users\Patten\fosscord\server\fosscord-server\cdn\node_modules\lambert-server\dist\Server.js:102:17 {
  expected: 507402,
  length: 507402,
  limit: 102400,
  type: 'entity.too.large'
}

Naidru avatar Sep 03 '21 20:09 Naidru

@Flam3rboy Please check the latest message of #339.

stilic avatar Sep 05 '21 09:09 stilic

I am seeing this error trying to upload a profile picture or a profile banner, even for a tiny 53KB image. Other images also don't work, including one which is only 23KB. Setting a server icon works more often, I can frequently set server icons while I can never seem to get a user icon or banner to set without getting this error. I can set the server icon to pictures I can never get my pfp to be set to.

If you notice in the error below, it says the limit is 102400, which suggests here you attempt to set the BodyParser limit to 10MB does not work here. 1024 * 1024 * 10 is equal to 10485760, so the value isn't applying here. This does however match the default the library has of 100KiB (102400 bytes). The behaviour still seems odd though, because my files are both below 100KiB, and thus should work, unless the request payload to set a profile picture has a lot of extra data in it other than the picture.

My client is Firefox 91.0.2 (64-bit) on macOS 11.5.1, on an M1 MacBook Pro.

The only way I'm aware of that my setup should be different is that I had to run npm config set package-lock false or else I would get EINTEGRITY errors out of npm install because of a failed checksum for the mpath module.

PayloadTooLargeError: request entity too large
    at readStream (/root/fosscord-server/cdn/node_modules/raw-body/index.js:155:17)
    at getRawBody (/root/fosscord-server/cdn/node_modules/raw-body/index.js:108:12)
    at read (/root/fosscord-server/cdn/node_modules/body-parser/lib/read.js:77:3)
    at jsonParser (/root/fosscord-server/cdn/node_modules/body-parser/lib/types/json.js:135:5)
    at Layer.handle [as handle_request] (/root/fosscord-server/bundle/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:317:13)
    at /root/fosscord-server/bundle/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:335:12)
    at next (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:275:10)
    at /root/fosscord-server/cdn/node_modules/lambert-server/dist/Server.js:102:17 {
  expected: 1477643,
  length: 1477643,
  limit: 102400,
  type: 'entity.too.large'
}
anne@clientlaptop ~ % stat -f%z /Users/anne/Desktop/E57IQtVXEAA-Hz7_cropped.jpg
57471
anne@clientlaptop ~ % stat -f%z /Users/anne/Pictures/e33c3f8fbe5afc4162c89cac0252710f6a5eb3e4r1-332-343v2_00.jpg
27689
anne@hostserver$ node -v 
v16.8.0
anne@hostserver$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
anne@hostserver$ git branch
* master
anne@hostserver$ git log --name-status HEAD^..HEAD
commit 528007872d37b17138275776daa705db6b63bb91 (HEAD -> master, origin/master, origin/HEAD)
Author: Flam3rboy <[email protected]>
Date:   Tue Sep 7 22:54:31 2021 +0200

    Update User.ts

M       util/src/entities/User.ts

git diff produces no output as I have not modified the codebase.

A few examples of images I have tried using:

E57IQtVXEAA-Hz7_cropped e33c3f8fbe5afc4162c89cac0252710f6a5eb3e4r1-332-343v2_00

Thank you for your time! This is a big of a big comment, but I wanted to give as much information as I could.

1byte2bytes avatar Sep 08 '21 07:09 1byte2bytes

The behaviour still seems odd though, because my files are both below 100KiB, and thus should work, unless the request payload to set a profile picture has a lot of extra data in it other than the picture.

I don't know the Discord API, but the size difference between the image I try to upload and what the server says it got is very significant, more than just some random user data and such if I had to guess.

Let's take the image on my laptop. It's 57471 bytes big.

anne@clientlaptop ~ % stat -f '%z' /Users/anne/Desktop/E57IQtVXEAA-Hz7_cropped.jpg
57471

If I upload it to my Fosscord instance, I get the error

PayloadTooLargeError: request entity too large
    at readStream (/root/fosscord-server/cdn/node_modules/raw-body/index.js:155:17)
    at getRawBody (/root/fosscord-server/cdn/node_modules/raw-body/index.js:108:12)
    at read (/root/fosscord-server/cdn/node_modules/body-parser/lib/read.js:77:3)
    at jsonParser (/root/fosscord-server/cdn/node_modules/body-parser/lib/types/json.js:135:5)
    at Layer.handle [as handle_request] (/root/fosscord-server/bundle/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:317:13)
    at /root/fosscord-server/bundle/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:335:12)
    at next (/root/fosscord-server/bundle/node_modules/express/lib/router/index.js:275:10)
    at /root/fosscord-server/cdn/node_modules/lambert-server/dist/Server.js:102:17 {
  expected: 1494875,
  length: 1494875,
  limit: 102400,
  type: 'entity.too.large'
}

1494875-57471 is 1437404, somewhere an extra 1.37MiB of data was in the payload from the client to the server.

1byte2bytes avatar Sep 08 '21 07:09 1byte2bytes

So, we need to set the limit proprety to 8mb. I will do a fix for.

stilic avatar Sep 08 '21 11:09 stilic

Hello Stilic,

  1. With this commit, my client can no longer connect at all.
socket requests upgrade /?encoding=json&v=9&compress=zlib-stream
[Gateway] Opcode Identify
Unkown key animated
Unkown key animated
[WebSocket] closed 4002
Screenshot 2021-09-08 at 16 10 13
  1. "1494875-57471 is 1437404, somewhere an extra 1.37MiB of data was in the payload from the client to the server.". Do you happen to know what this extra data is? It seems suspiciously large to me.

Thanks, Anne!

1byte2bytes avatar Sep 08 '21 15:09 1byte2bytes

The issue with the Unknown key animated is not related to this issue. Check maybe #295.

stilic avatar Sep 09 '21 05:09 stilic