from flask import Flask, request, render_template_string
import os
import zipfile
import tarfile
app = Flask(__name__)
@app.route('/')
def index():
return render_template_string('''
<form action="{{ url_for('upload_file') }}" method="post" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit">Upload</button>
</form>
''')
@app.route('/upload', methods=['POST'])
def upload_file():
file = request.files['file']
if file.filename.endswith('.zip'):
return parse_zip_file(file)
elif file.filename.endswith('.tar.gz'):
return parse_tar_gz_file(file)
else:
return 'Unsupported file type', 400
def parse_zip_file(file):
file_path = os.path.join('uploads', file.filename)
file.save(file_path)
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall('uploads')
return 'File uploaded and extracted successfully'
def parse_tar_gz_file(file):
file_path = os.path.join('uploads', file.filename)
file.save(file_path)
with tarfile.open(file_path, 'r') as tar_ref:
tar_ref.extractall('uploads')
return 'File uploaded and extracted successfully'
if __name__ == '__main__':
app.run()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2019-07-01 Python进阶(十一)----包,logging模块