我正在创建一个上传文件的方法但是我想检查文件大小,因为我只想允许5mb作为最大限制。
我想做这样的事情
def handle_uploaded_file(thisFile):
if thisFile > 5mb:
return "This file is more than 5mb"
else:
with open('some/file/' + str(thisFile), 'wb+') as destination:
for chunk in thisFile.chunks():
destination.write(chunk)
return "File has successfully been uploaded"
答案 0 :(得分:4)
irisctree<-ctree(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width)
plot(itisctree,type="simple")
信用转到django snippet
答案 1 :(得分:3)
使用._size
文件属性
if thisFile._size > 5242880:
return "This file is more than 5mb"
._size
以字节表示。 5242880 - 5MB
def handle_uploaded_file(thisFile):
if thisFile._size > 5242880:
return "This file is more than 5mb"
else:
with open('some/file/' + str(thisFile), 'wb+') as destination:
for chunk in thisFile.chunks():
destination.write(chunk)
return "File has successfully been uploaded"