|
10 | 10 | from .exceptions import ExceptionMap, UnboxException
|
11 | 11 | from .version import __version__
|
12 | 12 |
|
13 |
| -UNBOX_ENDPOINT = "https://api.unbox.ai/api" |
14 |
| -# UNBOX_ENDPOINT = "http://localhost:8080/api" |
| 13 | +# UNBOX_ENDPOINT = "https://api.unbox.ai/api" |
| 14 | +UNBOX_ENDPOINT = "http://localhost:8080/api" |
15 | 15 | UNBOX_STORAGE_PATH = os.path.expanduser("~/unbox/unbox-onpremise/userStorage")
|
16 | 16 |
|
17 | 17 |
|
@@ -196,6 +196,36 @@ def upload_blob_gcs(
|
196 | 196 | else:
|
197 | 197 | self._raise_on_respose(res)
|
198 | 198 |
|
| 199 | + def upload_blob_azure( |
| 200 | + self, endpoint: str, file_path: str, object_name: str = None, body=None |
| 201 | + ): |
| 202 | + """Generic method to upload data to Azure Blob Storage and create the appropriate resource |
| 203 | + in the backend. |
| 204 | + """ |
| 205 | + params = {"storageInterface": "azure", "objectName": object_name} |
| 206 | + presigned_json = self.get_request(endpoint, params=params) |
| 207 | + with open(file_path, "rb") as f: |
| 208 | + with tqdm( |
| 209 | + total=os.stat(file_path).st_size, |
| 210 | + unit="B", |
| 211 | + unit_scale=True, |
| 212 | + unit_divisor=1024, |
| 213 | + ) as t: |
| 214 | + wrapped_file = CallbackIOWrapper(t.update, f, "read") |
| 215 | + res = requests.put( |
| 216 | + presigned_json["url"], |
| 217 | + data=wrapped_file, |
| 218 | + headers={ |
| 219 | + "Content-Type": "application/x-gzip", |
| 220 | + "x-ms-blob-type": "BlockBlob", |
| 221 | + }, |
| 222 | + ) |
| 223 | + if res.ok: |
| 224 | + body["storagePath"] = presigned_json["storagePath"] |
| 225 | + return self.post_request(f"{endpoint}/{presigned_json['id']}", body=body) |
| 226 | + else: |
| 227 | + self._raise_on_respose(res) |
| 228 | + |
199 | 229 | def transfer_blob(self, endpoint: str, file_path: str, object_name: str, body=None):
|
200 | 230 | """Generic method to transfer data to the unbox folder and create the appropriate
|
201 | 231 | resource in the backend when using a local deployment.
|
|
0 commit comments