Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1038,15 +1038,26 @@ async def chunked_upload(upload_url: str, file: UploadFile, content_type: str, c
|
|
1038 |
for attempt in range(5): # 5 retries
|
1039 |
try:
|
1040 |
async with session.put(upload_url, data=chunk, headers=headers) as response:
|
1041 |
-
if response.status
|
1042 |
break
|
1043 |
-
|
|
|
|
|
|
|
|
|
1044 |
if attempt == 4: # Last attempt
|
|
|
1045 |
return False
|
1046 |
await asyncio.sleep(2 ** attempt) # Exponential backoff
|
1047 |
else:
|
1048 |
return False
|
1049 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1050 |
return True
|
1051 |
|
1052 |
async def get_file_size(file: UploadFile) -> int:
|
|
|
1038 |
for attempt in range(5): # 5 retries
|
1039 |
try:
|
1040 |
async with session.put(upload_url, data=chunk, headers=headers) as response:
|
1041 |
+
if response.status in [200, 201, 204]:
|
1042 |
break
|
1043 |
+
elif response.status == 308: # Resume Incomplete
|
1044 |
+
continue
|
1045 |
+
else:
|
1046 |
+
raise aiohttp.ClientError(f"Unexpected status code: {response.status}")
|
1047 |
+
except aiohttp.ClientError as e:
|
1048 |
if attempt == 4: # Last attempt
|
1049 |
+
print(f"Upload failed: {str(e)}")
|
1050 |
return False
|
1051 |
await asyncio.sleep(2 ** attempt) # Exponential backoff
|
1052 |
else:
|
1053 |
return False
|
1054 |
|
1055 |
+
# Verify the upload
|
1056 |
+
async with session.put(upload_url, headers={'Content-Range': f'bytes */{file_size}'}) as response:
|
1057 |
+
if response.status not in [200, 201, 204]:
|
1058 |
+
print(f"Upload verification failed: {response.status}")
|
1059 |
+
return False
|
1060 |
+
|
1061 |
return True
|
1062 |
|
1063 |
async def get_file_size(file: UploadFile) -> int:
|