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()) self.wfile.write(json.dumps({"error": str(e)}, ensure_ascii=False).encode())
def _handle_upload(self): def _handle_upload(self):
"""Принять файл и передать в Lucee чанками (обходит лимит тела запроса).""" """Принять файл и передать в Lucee (одним POST, лимиты k8s увеличены)."""
import uuid
from email.parser import BytesParser from email.parser import BytesParser
content_type = self.headers.get("Content-Type", "") content_type = self.headers.get("Content-Type", "")
@@ -301,7 +300,6 @@ class Handler(BaseHTTPRequestHandler):
filename = fn filename = fn
file_data = part.get_payload(decode=True) file_data = part.get_payload(decode=True)
else: else:
# Может быть поле contract_id
disp = part.get("Content-Disposition", "") disp = part.get("Content-Disposition", "")
if "name=\"contract_id\"" in disp: if "name=\"contract_id\"" in disp:
contract_id = part.get_payload(decode=True).decode("utf-8", errors="ignore").strip() 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") self._send_error_cors(400, "no file in request")
return return
# Режем на чанки (новый HTTP/2 connection на каждый — Lucee сбрасывает стрим) with httpx.Client(http2=True, timeout=60, verify=False) as client:
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:
resp = client.post( resp = client.post(
f"{LUCEE_URL}/chunk.cfm?action=assemble", f"{LUCEE_URL}/upload.cfm",
json={"upload_id": upload_id, "contract_id": contract_id}, data={"filename": filename, "data": "\\x" + file_data.hex()},
) )
if resp.status_code == 200: if resp.status_code == 200:
self.send_response(200) self.send_response(200)
@@ -346,7 +320,7 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers() self.end_headers()
self.wfile.write(resp.content) self.wfile.write(resp.content)
else: 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): def _handle_unzip_upload(self):
"""Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива.""" """Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива."""