v1.0.142: direct upload — one piece, Lucee k8s limits increased

This commit is contained in:
2026-06-23 11:33:21 +04:00
parent 9b11b62b7f
commit 800ae657f6
+5 -31
View File
@@ -280,8 +280,7 @@ class Handler(BaseHTTPRequestHandler):
self.wfile.write(json.dumps({"error": str(e)}, ensure_ascii=False).encode())
def _handle_upload(self):
"""Принять файл и передать в Lucee чанками (обходит лимит тела запроса)."""
import uuid
"""Принять файл и передать в Lucee (одним POST, лимиты k8s увеличены)."""
from email.parser import BytesParser
content_type = self.headers.get("Content-Type", "")
@@ -301,7 +300,6 @@ class Handler(BaseHTTPRequestHandler):
filename = fn
file_data = part.get_payload(decode=True)
else:
# Может быть поле contract_id
disp = part.get("Content-Disposition", "")
if "name=\"contract_id\"" in disp:
contract_id = part.get_payload(decode=True).decode("utf-8", errors="ignore").strip()
@@ -310,34 +308,10 @@ class Handler(BaseHTTPRequestHandler):
self._send_error_cors(400, "no file in request")
return
# Режем на чанки (новый HTTP/2 connection на каждый — Lucee сбрасывает стрим)
CHUNK = 20000
upload_id = str(uuid.uuid4())
raw = file_data
total = (len(raw) + CHUNK - 1) // CHUNK
for i in range(total):
chunk = raw[i*CHUNK:(i+1)*CHUNK]
with httpx.Client(http2=True, timeout=30, verify=False) as client:
r = client.post(
f"{LUCEE_URL}/chunk.cfm?action=put",
json={
"upload_id": upload_id,
"chunk_index": i,
"total_chunks": total,
"filename": filename,
"data": chunk.hex(),
},
)
if r.status_code != 200:
self._send_error_cors(502, f"chunk {i+1}/{total} failed: HTTP {r.status_code}")
return
# Собрать чанки
with httpx.Client(http2=True, timeout=60) as client:
with httpx.Client(http2=True, timeout=60, verify=False) as client:
resp = client.post(
f"{LUCEE_URL}/chunk.cfm?action=assemble",
json={"upload_id": upload_id, "contract_id": contract_id},
f"{LUCEE_URL}/upload.cfm",
data={"filename": filename, "data": "\\x" + file_data.hex()},
)
if resp.status_code == 200:
self.send_response(200)
@@ -346,7 +320,7 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(resp.content)
else:
self._send_error_cors(502, f"assemble failed: HTTP {resp.status_code}")
self._send_error_cors(502, f"Lucee error: {resp.status_code}")
def _handle_unzip_upload(self):
"""Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива."""