Skip to content

Commit 107d227

Browse files
mapleeithanxiao
andauthored
fix(pushpull): allow uploading docarray max size 4GB (#43)
Co-authored-by: Han Xiao <[email protected]>
1 parent 97725ed commit 107d227

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docarray/array/mixins/io/pushpull.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
import io
2+
import json
23
from contextlib import nullcontext
3-
from typing import Type, TYPE_CHECKING, Optional
4+
from typing import Type, TYPE_CHECKING
5+
from functools import lru_cache
6+
from urllib.request import Request, urlopen
47

58
from ....helper import get_request_header
69

710
if TYPE_CHECKING:
811
from ....types import T
912

1013

14+
@lru_cache()
15+
def _get_cloud_api() -> str:
16+
"""Get Cloud Api for transmiting data to the cloud.
17+
18+
:raises RuntimeError: Encounter error when fetching the cloud Api Url.
19+
:return: Cloud Api Url
20+
"""
21+
try:
22+
req = Request(
23+
'https://api.jina.ai/hub/hubble.json',
24+
headers={'User-Agent': 'Mozilla/5.0'},
25+
)
26+
with urlopen(req) as resp:
27+
u = json.load(resp)['url']
28+
except Exception as ex:
29+
raise RuntimeError(
30+
f'Can not fetch Cloud API address from {req.full_url}'
31+
) from ex
32+
33+
return u
34+
35+
1136
class PushPullMixin:
1237
"""Transmitting :class:`DocumentArray` via Jina Cloud Service"""
1338

14-
_service_url = 'https://apihubble.jina.ai/v2/rpc/da.'
39+
_service_url = _get_cloud_api() + '/v2/rpc/da.'
1540
_max_bytes = 4 * 1024 * 1024 * 1024
1641

1742
def push(self, token: str, show_progress: bool = False) -> None:

0 commit comments

Comments
 (0)