django-ckeditor-5 icon indicating copy to clipboard operation
django-ckeditor-5 copied to clipboard

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

Open tuhe opened this issue 1 year ago • 2 comments

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 avatar Aug 27 '24 13:08 tuhe

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:

  • set up ckeditor5 using default settings
  • download this picture https://www.freepik.com/free-vector/night-ocean-landscape-full-moon-stars-shine_17740155.htm#query=desktop%20wallpaper&position=10&from_view=keyword&track=ais_hybrid&uuid=807d8a97-8392-4a83-8860-19c6cf82a1cc
  • copy-paste a region into the ckeditor5 field (works)
  • copy paste the entire image into the ckeditor5 field (does not work).

tuhe avatar Aug 27 '24 14:08 tuhe

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)

tuhe avatar Aug 27 '24 20:08 tuhe

@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

goapunk avatar Sep 16 '24 14:09 goapunk

@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.

cfdbwrbq avatar Nov 21 '24 08:11 cfdbwrbq