Forem Creators and Builders 🌱

Discussion on: Image upload configuration issue

Collapse
 
djuber profile image
Daniel Uber

I did see that "unexpected token" error during testing, if a 404 or other error page was returned instead of a json response. The "<" unexpected token is almost surely a doctype header for an html response, this should be visible in the network traffic (and probably an error will show in the forem server logs).

I think that's not completely related to the article creation issue (where you can't save a post with a cover image) and would show instead when uploading (where uploads failed for some reason, and gave that json parse error).

Thread Thread
 
9comindia profile image
9comindia Author • Edited on

Image Upload failed and the network traffic shows the below log.
The image size is 1.58MB and resolution 2448x3264.

413 (Request Entity Too Large)
(anonymous) @ base.js:7637
generateMainImage @ actions.js?2261:88
ArticleCoverImage.this.handleMainImageUpload @ ArticleCoverImage.jsx?b917:81
I @ preact.module.js?da65:1
O.e.
hb.e._hb @ base.js:7319

Issue 1: The image should have been handled because the size < 25 MB and resolution < 4096x4096
Issue 2: Should have displayed the proper error message for end user instead of the "Unexpected token < in JSON at position 0"

The same issue happens for both image upload and cover image upload.

(anonymous) @ base.js:7637
generateMainImage @ actions.js?2261:88
handleInsertionImageUpload @ ImageUploader.jsx?6697:168
I @ preact.module.js?da65:1
O.e.hb.e.hb @ base.js:7319

Could this be an issue in the code or configuration?

Thread Thread
 
djuber profile image
Daniel Uber

Thanks for the extra detail - yes - if this is happening for both body image upload and cover image upload it's a separate issue from the url validation you initially described.

I would suspect the error could be raised by Traefik rather than rails, based on one of the settings shown here doc.traefik.io/traefik/middlewares... - but I don't see that we enable the "buffering" middleware in the traefik config so I'm less confident of that. One other possible culprit could be rack (the ruby web application framework) or puma ( the actual http server process) but I'm not seeing anything obvious there that would raise a payload too large error when handling uploads. I do see the openresty nginx configuration explicitly sets max body size to 0 - which overrides the default of 1MB.

This definitely does not happen locally in development (I am able to upload a 1.78MB JPG file and it's saved correctly) with just puma listening on port 3000, so it's unlikely to be the forem code (rather than something "upstream" in the request cycle, like traefik or nginx).

Thread Thread
 
9comindia profile image
9comindia Author • Edited on

Superb @djuber , this really helped me.
I don't have traefik and openresty in my local environment, just the nginx.
After setting "max body size to 0" in nginx, the error is gone.
thank you very much.

And the url validation issue was resolved when replaced "development" to "production" in files wherever I found development.

I am yet to find a proper way to run "bin/rails s -p 3000 -b 0.0.0.0" in production, which is starting the rails in development environment.