fix: 视频工具响应改二进制流+标准Content-Disposition(修复multipart包裹导致的客户端文件损坏); 修cgi bool异常
This commit is contained in:
1 parent
0ec5624add
commit
6bc2120c05
2 files changed
+18
-8
No files matched your search
@@ -900,7 +900,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
env = {"REQUEST_METHOD": "POST", "CONTENT_TYPE": ctype, "CONTENT_LENGTH": str(length)}
|
||||
fs = cgi.FieldStorage(fp=io.BytesIO(raw), environ=env, keep_blank_values=True)
|
||||
fobj = fs["file"] if ("file" in fs.keys()) else None
|
||||
if not fobj or not getattr(fobj, "filename", None):
|
||||
if fobj is None or not fobj.filename:
|
||||
self._reply(400, json.dumps({"code": 400, "message": "缺少视频文件"}, ensure_ascii=False).encode(), "application/json")
|
||||
return
|
||||
fname = os.path.basename(fobj.filename or "video")
|
||||
@@ -931,15 +931,14 @@ class Handler(BaseHTTPRequestHandler):
|
||||
out = f.read()
|
||||
base = os.path.splitext(fname)[0][:80]
|
||||
out_name = base + "-out." + out_ext
|
||||
body = (b"--vidboundary\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" +
|
||||
out_name.encode("utf-8") + b"\"\r\nContent-Type: application/octet-stream\r\n\r\n" +
|
||||
out + b"\r\n--vidboundary--\r\n")
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "multipart/form-data; boundary=vidboundary")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.send_header("Content-Type", "application/octet-stream")
|
||||
self.send_header("Content-Length", str(len(out)))
|
||||
self.send_header("Content-Disposition",
|
||||
"attachment; filename=\"result." + out_ext + "\"; filename*=UTF-8''" + parse.quote(out_name))
|
||||
self.send_header("X-Duration-Seconds", str(round(duration, 2)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
self.wfile.write(out)
|
||||
except ValueError as e:
|
||||
self._reply(400, json.dumps({"code": 400, "message": str(e)}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
except Exception as e: # noqa: BLE001
|
||||
|
||||
Reference in new issue
Block a user