Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small images upload, large images do not (Size 0?) #240

Open
tuhe opened this issue Aug 27, 2024 · 4 comments
Open

Small images upload, large images do not (Size 0?) #240

tuhe opened this issue Aug 27, 2024 · 4 comments

Comments

@tuhe
Copy link

tuhe commented Aug 27, 2024

Hi!

Thank you for your work on the plugin. I am using the plugin using the default setup from the README outside of the django admin. I can upload / see small images without any problems, but if I copy-paste a large image (i.e. a desktop wallpaper or similar) I get a pop-up error: "Couldn't upload file: image.png.". The error arise from the code Image.open(f) in:

def image_verify(f):
    try:
        Image.open(f).verify()
    except OSError:
        raise NoImageException

https://github.com/hvlads/django-ckeditor-5/blob/master/django_ckeditor_5/views.py#L57

and I think it is because f.size show 0 bytes (this is not the case for small images). My best guess is that this might be happening on the frontend, perhaps due to a limit (?), but I cannot find an option to set in the settings.py file (changing CKEDITOR_5_MAX_FILE_SIZE = 10 does not do anything but my understanding is also that the default is infinite size). Other parts of the application has no problem with large files (100 mb) so I don't think it is a middleware issue or similar. Any help would be greatly appreciated!

@tuhe
Copy link
Author

tuhe commented Aug 27, 2024

I tried to set the default handler to MemoryFileHandler in settings.py using:

FILE_UPLOAD_HANDLERS = [
    "django.core.files.uploadhandler.MemoryFileUploadHandler",
    # "django.core.files.uploadhandler.TemporaryFileUploadHandler",
]

but no luck. As far as I can tell, the image is simply not being uploaded correctly (i.e., request.FILES['upload'] has size 0) and I wonder if it is a front-end issue of some sort. The image is not too big and the problem can be re-produced by:

@tuhe
Copy link
Author

tuhe commented Aug 27, 2024

This is happening with a signed in user, however, the behavior is completely reproducible (small images upload and save, large images do not). It occurs both in production and on a restarted development server. Is there anything I can do to illuminate what the problem is?
(update: this was a response to a now deleted post)

@goapunk
Copy link
Contributor

goapunk commented Sep 16, 2024

@tuhe I tried reproducing it with your steps with the example blog app in this repo and I can successfully upload the image via the upload button and via copy and paste. Maybe some more information about browser and operating system would be helpful

@cfdbwrbq
Copy link

@tuhe most likely the problem is in nginx server (or Apache)
adding client_max_body_size 1G; to server context solves the problem of loading large files
ps
For Nginx - the default value for client_max_body_size directive is 1 MiB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants