djangoimageresizepython-imaging-librarydjango-filebrowser

Django filebrowser - resize before upload


Is it possible to resize image before upload using django filebrowser without keeping original image size on server ?


Solution

  • Create pre_upload callback that will resize your image before saving.

    from filebrowser import signals
    
    def pre_upload_callback(sender, **kwargs):
        """
        Receiver function called before an upload starts.
        """
        print "Pre Upload Callback"
        print "kwargs:", kwargs
        # your code HERE
    signals.filebrowser_pre_upload.connect(pre_upload_callback)
    

    Filebrowser documentation on signals

    Alternatively, if pre_upload hook doesn't work (because the file is not there yet) you can use post_upload hook, and modify the file in place.