Spaces:
Sleeping
Sleeping
Update test.py
Browse files
test.py
CHANGED
@@ -131,6 +131,13 @@ async def auth_google(request: Request):
|
|
131 |
|
132 |
return {"attachment_count":attachment_no,"attachment_content":data_new}
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
@app.websocket("/ws")
|
135 |
async def test_websocket(websocket: WebSocket):
|
136 |
#This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
|
@@ -271,10 +278,12 @@ async def test_websocket(websocket: WebSocket):
|
|
271 |
if data:
|
272 |
data_new[filename]=str(data[:10])
|
273 |
attachment_content = base64.urlsafe_b64decode(data.encode("UTF-8"))
|
274 |
-
await websocket.send_json({"filename": filename})
|
275 |
-
await websocket.send_bytes(attachment_content)
|
|
|
|
|
276 |
attachment_no+=1
|
277 |
-
time.sleep(2)
|
278 |
# await websocket.send_json({filename:data})
|
279 |
|
280 |
# yield f"data: {str(data_new)}\n\n"
|
|
|
131 |
|
132 |
return {"attachment_count":attachment_no,"attachment_content":data_new}
|
133 |
|
134 |
+
|
135 |
+
async def send_chunked_data(websocket: WebSocket, filename: str, data: str):
|
136 |
+
chunk_size = 1024 # Set an appropriate chunk size
|
137 |
+
for i in range(0, len(data), chunk_size):
|
138 |
+
await websocket.send_json({"filename": filename, "data_chunk": data[i:i + chunk_size]})
|
139 |
+
await asyncio.sleep(0.1)
|
140 |
+
|
141 |
@app.websocket("/ws")
|
142 |
async def test_websocket(websocket: WebSocket):
|
143 |
#This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
|
|
|
278 |
if data:
|
279 |
data_new[filename]=str(data[:10])
|
280 |
attachment_content = base64.urlsafe_b64decode(data.encode("UTF-8"))
|
281 |
+
# await websocket.send_json({"filename": filename})
|
282 |
+
# await websocket.send_bytes(attachment_content)
|
283 |
+
await send_chunked_data(websocket, filename, data)
|
284 |
+
|
285 |
attachment_no+=1
|
286 |
+
# time.sleep(2)
|
287 |
# await websocket.send_json({filename:data})
|
288 |
|
289 |
# yield f"data: {str(data_new)}\n\n"
|