FileUpLoad.read():
特点:直接读取所有文件到内存,不建议使用
缺点:若文件较大,有可能造成内存溢出
FileUpLoad.chunk():
特点:按块返回文件,通过在for循环中进行迭代,可以将大文件按块写入到服务器中;
myFile.multiple_chunks():
特点:判断文件大小,若大于特定值,返回True,否则,返回FALSE 可以协调read和chunk
def handle_upload_file(file): try: print(file) path = os.path.dirname(os.path.dirname(__file__)) + '/static/file/' if not os.path.exists(path): os.makedirs(path) f = open(path + file.name, 'wb+') if file.multipel_chunks: for chunk in file.chunks(): f.write(chunk) f.close() res = 1 return res else: file = file.read() f.write(file) f.close() res = 1 return res except Exception as e: print(e) res = 0 return res