v1.0.143: chunked upload 10KB — restore after Lucee limit still ~30KB
This commit is contained in:
@@ -280,7 +280,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.wfile.write(json.dumps({"error": str(e)}, ensure_ascii=False).encode())
|
||||
|
||||
def _handle_upload(self):
|
||||
"""Принять файл и передать в Lucee (одним POST, лимиты k8s увеличены)."""
|
||||
"""Принять файл и передать в Lucee чанками (лимит ingress ~30KB)."""
|
||||
import uuid
|
||||
from email.parser import BytesParser
|
||||
|
||||
content_type = self.headers.get("Content-Type", "")
|
||||
@@ -308,10 +309,32 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._send_error_cors(400, "no file in request")
|
||||
return
|
||||
|
||||
CHUNK = 10000 # 10KB raw → 20KB hex → помещается
|
||||
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, verify=False) as client:
|
||||
resp = client.post(
|
||||
f"{LUCEE_URL}/upload.cfm",
|
||||
data={"filename": filename, "data": "\\x" + file_data.hex()},
|
||||
f"{LUCEE_URL}/chunk.cfm?action=assemble",
|
||||
json={"upload_id": upload_id, "contract_id": contract_id},
|
||||
)
|
||||
if resp.status_code == 200:
|
||||
self.send_response(200)
|
||||
@@ -320,7 +343,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
self.wfile.write(resp.content)
|
||||
else:
|
||||
self._send_error_cors(502, f"Lucee error: {resp.status_code}")
|
||||
self._send_error_cors(502, f"assemble failed: HTTP {resp.status_code}")
|
||||
|
||||
def _handle_unzip_upload(self):
|
||||
"""Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива."""
|
||||
|
||||
Reference in New Issue
Block a user