zoukankan      html  css  js  c++  java
  • Python shutil模块

    参考链接: https://www.cnblogs.com/zhangboblogs/p/7821702.html

          https://www.cnblogs.com/xiangsikai/p/7787101.html

    找了一圈的博客发现大大小小都有问题,还是看源码吧

    @app.route('/index/', methods=['GET', 'POST'])
    def index():
        import os
        import shutil
        if request.method == 'GET':
            return render_template('index.html')
        # POST
        file_obj = request.files.get('code')
        # print(file_obj)     # <FileStorage: 'bbs.zip' ('application/zip')>
        # print(file_obj.filename)    # bbs.zip
        print(type(file_obj))   # <class 'werkzeug.datastructures.FileStorage'>
        # from werkzeug.datastructures import FileStorage   # 查看源码
        file_path = os.path.join(os.getcwd(), 'files', file_obj.filename)
        # print(file_path)
        file_obj.save(file_path)
        # 解压
        extract_dir = os.path.join(os.getcwd(), 'files')
        shutil.unpack_archive(file_path, extract_dir=extract_dir)
        # save(self, dst, buffer_size=16384)  dst是目标文件,包括文件名
    
        return '上传成功'
  • 相关阅读:
    [APIO2007]风铃
    [APIO2011]方格染色
    [APIO2016]烟火表演
    [APIO2013]机器人
    [APIO2015]巴厘岛的雕塑
    [APIO2015]八邻旁之桥
    [APIO2010]特别行动队
    [APIO2015]雅加达的摩天楼
    WC2019游记
    退役前的做题记录3.0
  • 原文地址:https://www.cnblogs.com/wt7018/p/11609202.html
Copyright © 2011-2022 走看看