Is there a file size limit or extension limit in wagtail?

旧城冷巷雨未停 提交于 2019-12-11 14:20:21

问题


I have a very simple model (Product) which is used as an InlinePanel in a page.

Product has a FileField which works fine as long as I upload small files, but as soon as I upload a large file (>5MB), I somehow get an CSRF error. Both on local and on production.

It is not an issue with nginx max upload size.

Is there a file size limit or extension limit in wagtail?


回答1:


Yes, this comes baked into wagtail. If you add the following setting to your settings.py (or whatever your main settings file is), you'll be able to restrict upload sizes.

WAGTAILIMAGES_MAX_UPLOAD_SIZE = 15 * 1024 * 1024   # 15mb

The docs briefly cover this, too. Here's the link: http://docs.wagtail.io/en/v2.1.1/advanced_topics/settings.html#maximum-upload-size-for-images

If you need to change the file size from 15mb to anything else, just change that 15 in the settings line to the number of mb you want to limit it to.




回答2:


In some cases, you might have configured a temporary directory for large file downloads.

In my case this was:

 FILE_UPLOAD_TEMP_DIR = str(ROOT_DIR('tmp'))

If this directory is not created, you cannot upload large files, but small files will work fine. Simply create the directory locally and on production.

This bug is extremely hard to debug, as the wagtail admin interface will simply say that the upload fails, and somehow it will even yield a CSRF error.



来源:https://stackoverflow.com/questions/51332838/is-there-a-file-size-limit-or-extension-limit-in-wagtail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!