zoukankan      html  css  js  c++  java
  • 后端文件接收resd()和chunk的区别

    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

     

  • 相关阅读:
    GitHub Android Libraries Top 100 简介
    GitHub Top 100 的项目(iOS)
    iOS 学习资源
    HTTP和GET/POST请求(NSURLConnection)
    RunLoop
    HTML5 拖放
    网络安全与加密
    Cocoapods的安装
    iOS中的单例模式
    SDWebImage
  • 原文地址:https://www.cnblogs.com/lamb2018/p/11274281.html
Copyright © 2011-2022 走看看