zoukankan      html  css  js  c++  java
  • django文件上传下载

    def update(req: django.http.HttpRequest):
        if req.method == "POST":
            print("has file")
            with open("f:/file", "wb") as f:
                print("get f")
                print(req.FILES)
                for i in req.FILES["file_name"].chunks():
                    f.write(i)
        return render(req, "first/index.html")
    
    # 使用流式传输
    def download_bigfile(request):
        file_name = 文件名
    
        def openFile(fileName):
            with open(fileName, "rb") as f:
                while True:
                    c = f.read(1024)
                    if c:
                        yield c
                    else:
                        break
    
        response = StreamingHttpResponse(openFile(file_name))
        # 要指定 http 头
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="{0}"'.format(file_name)
        return response
  • 相关阅读:
    隔离级别
    分析Hello2代码
    正则表达式
    Filter and servlet
    部署描述符
    Annotation
    LDAP and Implementation
    Restful levels and Hateoas
    servlet injection analysis
    隔离级别
  • 原文地址:https://www.cnblogs.com/zhangzixian/p/11528294.html
Copyright © 2011-2022 走看看