Skip to content

Commit 2c410da

Browse files
committed
Closes UNB-2649 [CLIENT] Make local storage also return a faux presigned_url
1 parent 08f3082 commit 2c410da

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

unboxapi/api.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import uuid
43
from enum import Enum
54

65
import requests
@@ -31,9 +30,6 @@ class StorageType(Enum):
3130

3231
STORAGE = StorageType.AWS
3332
UNBOX_ENDPOINT = "https://api-staging.unbox.ai/v1"
34-
# UNBOX_ENDPOINT = "https://api.unbox.ai/v1"
35-
# UNBOX_ENDPOINT = "http://localhost:8080/v1"
36-
UNBOX_STORAGE_PATH = os.path.expanduser("~/unbox/unbox-onpremise/userStorage")
3733

3834

3935
class Api:
@@ -267,12 +263,13 @@ def transfer_blob(self, endpoint: str, file_path: str, object_name: str, body=No
267263
"""Generic method to transfer data to the unbox folder and create the appropriate
268264
resource in the backend when using a local deployment.
269265
"""
270-
id = uuid.uuid4()
271-
blob_path = f"{UNBOX_STORAGE_PATH}/{endpoint}/{id}"
266+
params = {"storageInterface": "local", "objectName": object_name}
267+
presigned_json = self.get_request(f"{endpoint}/presigned-url", params=params)
268+
blob_path = presigned_json["storageUri"].replace("local://", "")
272269
try:
273270
os.makedirs(blob_path, exist_ok=True)
274271
except OSError:
275272
raise UnboxException(f"Directory {blob_path} cannot be created")
276273
shutil.copyfile(file_path, f"{blob_path}/{object_name}")
277-
body["storageUri"] = f"local://{blob_path}"
274+
body["storageUri"] = presigned_json["storageUri"]
278275
return self.post_request(f"{endpoint}", body=body)

0 commit comments

Comments
 (0)