【发布时间】:2020-10-26 17:07:30
【问题描述】:
我想限制保存到数据库的图像(Base64)的大小。例如,我希望图像的最大大小为 100KB,我该怎么做?我正在使用 Django。
【问题讨论】:
-
如果有帮助,请检查此stackoverflow.com/questions/24373341/…
-
会检查..谢谢
标签: python html css django database
我想限制保存到数据库的图像(Base64)的大小。例如,我希望图像的最大大小为 100KB,我该怎么做?我正在使用 Django。
【问题讨论】:
标签: python html css django database
class CreateForm(forms.ModelForm):
#the size you want it to be, example for 2 mb is given below
max_upload_limit = 2*1024*1024
#override clean function to something like this
clean(self):
cleaned_data = super().clean()
pic = cleaned_data.get('picture')
if pic is None:
return
if len(pic) > self.max_upload_limit:
self.add_error('picture', "File must be < "+self.max_upload_limit_text+" bytes")
这显示了如何使用 Django 表单来限制图像大小。
【讨论】: