django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.76k stars 577 forks source link

File upload result with error 500 since statics migration to AWS S3 #955

Closed Vesli closed 2 years ago

Vesli commented 7 years ago

Hi, I'm a bit confused about django-filer behaviour. To explain quickly: I recently deployed my project into a staging server. Filer was locally running and then I decided to migrate my statics to aws s3 / cloudfront.

Since then, (migrate statics works, everything correctly loaded) when I try to upload an image to filer, I've this error: `dropzone.min.js:77 POST domain.com/admin/filer/clipboard/operations/upload/no_folder/ 500 (Internal Server Error) c.submitRequest @ dropzone.min.js:77

dropzone.init.js:38 TypeError: Cannot read property 'API' of undefined at showError (dropzone.init.js:34) at c.error (dropzone.init.js:123) at c.e.emit (dropzone.min.js:29) at c._errorProcessing (dropzone.min.js:78) at dropzone.min.js:73 at XMLHttpRequest. (dropzone.min.js:75)`

(same with direct upload from fileuploader) conf: Django==1.9.12 django-filer==1.2.5 django-mptt==0.8.6 django-storages==1.5.2

python 3+

All the static files are correctly loaded (so no JQ problem or whatever). Except that, shouldn't it be: domain.com/admin/filer/clipboard/operations => s3domain.com/admin/filer/... ?

The only difference compare to before are those lines:


    STATICFILES_STORAGE = 'project.storage.StaticStorage'
    STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)

    MEDIAFILES_LOCATION = 'media'
    MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
    DEFAULT_FILE_STORAGE = 'project.storage.MediaStorage'

    FILER_STORAGES = {
        'public': {
            'main': {
                'ENGINE': 'project.storage.MediaStorage',
                'OPTIONS': {
                    'location': STATICFILES_LOCATION,
                    'base_url': MEDIA_URL,
                },
                'UPLOAD_TO': 'filer.utils.generate_filename.by_date',
                'UPLOAD_TO_PREFIX': 'public',
            },
            'thumbnails': {
                'ENGINE': 'project.storage.MediaStorage',
                'OPTIONS': {
                    'location': STATICFILES_LOCATION,
                    'base_url': MEDIA_URL + 'thumbnails',
                },
                'THUMBNAIL_OPTIONS': {
                    'base_dir': 'thumbnails',
                },
            },
        },
        'private': {
            'main': {
                'ENGINE': 'project.storage.MediaStorage',
                'OPTIONS': {
                    'base_url': MEDIA_URL,
                },
                'UPLOAD_TO': 'filer.utils.generate_filename.by_date',
                'UPLOAD_TO_PREFIX': 'private',
            },
            'thumbnails': {
                'ENGINE': 'project.storage.MediaStorage',
                'OPTIONS': {
                    'base_url': MEDIA_URL + 'thumbnails',
                },
            },
        },
    }```

The very basic media storage:

`class MediaStorage(S3Boto3Storage):
    location = settings.MEDIAFILES_LOCATION`

Soo I'm a bit lost, am I missing something? 

Many thanks guys, and keep up the good work behind this plugin :)
Vesli commented 7 years ago

I put back the debug to True in order to have more infos.

As I'm lazy and wanted to directly have the error template, I tried to delete a folder from the admin and here is the error message:

ValueError at /admin/filer/folder/1/delete/ Required parameter name not set Request Method: POST Request URL: http://project.com/admin/filer/folder/1/delete/?_pick=file&_popup=1 Django Version: 1.9.12 Exception Type: ValueError Exception Value:
Required parameter name not set Exception Location: /var/www/webapps/lib/python3.4/site-packages/boto3/resources/base.py in init, line 119 Python Executable: /var/www/webapps/bin/python3

python-force commented 7 years ago

I have the same issue with AWS S3 500 Errors in browser console, then it will say upload complete and no images, or it is frozen on 0/4 images and nothing. Running 1.11.4 and Python 2.7 - 500 error is dropzone.min.js:77

elebumm commented 6 years ago

Jesus H Murphy, this took me over 3 hours to figure out so I hope this will help someone who feels hopeless.

One of the maintainers of this repo says that this error could lead to ANY backend problem. I adjusted the read and write permissions and that wasn't it. I tried configuring some NGINX settings and that wasn't working for me either. I found the real reason why this wasn't working.

My PostreSQL database.

The problem was the index was completely wrong when trying to upload on not only the filer app but the easy_thumbnail one as well. Basically, when I migrated my database over it didn't copy over any indexes. This drove me crazy. Here is how I solved it.

Log into your Postgres database and enter password: psql -U my_user my_database

In another tab, navigate to your project directory and run these: python manage.py sqlsequencereset easy_tumbnails python manage.py sqlsequencereset filer

The code here will then spit out some PSQL code that you will enter when you enter the PSQL command line from what we did on the first step. Insert each SELECT statement in individually. Unless you are a pro and know how to do it without executing...

Quit out of your PSQL command line: \q

Optional: restart your web server and gunicorn.

This is how I got mine to work. I messed around with SQL commands, NGINX server configs and this is what worked for me.

TL;DR check your logs for your web server, database and gunicorn.

python-force commented 6 years ago

I had that same problem but look what I have found out, either easy_thumbnails or django-cropping which is based on easy_thumbnails duplicating data, have opened this a while ago... when I solved it, it was insane...

https://github.com/SmileyChris/easy-thumbnails/issues/477 https://github.com/jonasundderwolf/django-image-cropping/issues/122

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This will now be closed due to inactivity, but feel free to reopen it.