v1.0.120: fix ZIP — use FormData on client, parse multipart on VM

This commit is contained in:
2026-06-23 08:09:05 +04:00
parent 5c6fe0da00
commit b20ec58aff
2 changed files with 26 additions and 5 deletions
+24 -2
View File
@@ -280,12 +280,34 @@ class Handler(BaseHTTPRequestHandler):
def _handle_unzip_upload(self):
"""Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива."""
import zipfile, io
# Читаем multipart form data
content_type = self.headers.get("Content-Type", "")
length = int(self.headers.get("Content-Length", 0))
data = self.rfile.read(length)
body = self.rfile.read(length)
# Извлекаем ZIP из multipart
boundary = content_type.split("boundary=")[1].strip()
parts = body.split(b"--" + boundary.encode())
zip_data = None
for part in parts:
if b"filename=" in part:
# Отделяем заголовки от тела
header_end = part.find(b"\r\n\r\n")
if header_end > 0:
zip_data = part[header_end+4:]
# Убираем trailing \r\n и boundary
if zip_data.endswith(b"\r\n"):
zip_data = zip_data[:-2]
break
if not zip_data:
self.send_error(400, "no file in request")
return
results = []
try:
with zipfile.ZipFile(io.BytesIO(data)) as zf:
with zipfile.ZipFile(io.BytesIO(zip_data)) as zf:
for name in zf.namelist():
# Только файлы из корня (без папок), пропускаем директории
if name.endswith('/') or '/' in name: