Skip to content

Commit 3b618bc

Browse files
committed
Upload object names - next step towards decentralized file storage
1 parent d03b14d commit 3b618bc

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

unboxapi/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ def add_model(
411411
trainSampleLabelColumnName=train_sample_label_column_name,
412412
)
413413
print("Uploading model to Unbox...")
414-
modeldata = self.upload(endpoint, tarfile_path, payload)
414+
modeldata = self.upload(
415+
endpoint=endpoint,
416+
file_path=tarfile_path,
417+
object_name="tarfile",
418+
body=payload,
419+
)
415420
os.remove("template_model.py")
416421
return Model(modeldata)
417422

@@ -560,6 +565,7 @@ def add_dataset(
560565
>>> dataset.to_dict()
561566
"""
562567
file_path = os.path.expanduser(file_path)
568+
object_name = "original.csv"
563569
if not os.path.isfile(file_path):
564570
raise UnboxException("File path does not exist.")
565571
if label_column_name in feature_names:
@@ -611,7 +617,14 @@ def add_dataset(
611617
featureNames=feature_names,
612618
categoricalFeaturesMap=categorical_features_map,
613619
)
614-
return Dataset(self.upload(endpoint, file_path, payload))
620+
return Dataset(
621+
self.upload(
622+
endpoint=endpoint,
623+
file_path=file_path,
624+
object_name=object_name,
625+
body=payload,
626+
)
627+
)
615628

616629
def add_dataframe(
617630
self,

unboxapi/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def put_request(self, endpoint: str, body=None, files=None, data=None):
143143
data=data,
144144
)
145145

146-
def upload_blob_s3(self, endpoint: str, file_path: str, body=None):
146+
def upload_blob_s3(
147+
self, endpoint: str, file_path: str, object_name: str, body=None
148+
):
147149
"""Generic method to upload data to S3 storage and create the appropriate resource
148150
in the backend.
149151
"""
@@ -189,7 +191,7 @@ def upload_blob_gcs(self, endpoint: str, file_path: str, body=None):
189191
else:
190192
self._raise_on_respose(res)
191193

192-
def transfer_blob(self, endpoint: str, file_path: str, body=None):
194+
def transfer_blob(self, endpoint: str, file_path: str, object_name: str, body=None):
193195
"""Generic method to transfer data to the unbox folder and create the appropriate
194196
resource in the backend when using a local deployment.
195197
"""
@@ -199,6 +201,6 @@ def transfer_blob(self, endpoint: str, file_path: str, body=None):
199201
os.makedirs(blob_path, exist_ok=True)
200202
except OSError as _:
201203
raise UnboxException(f"Directory {blob_path} cannot be created")
202-
shutil.copyfile(file_path, f"{blob_path}/{id}")
203-
body["storagePath"] = f"local://{blob_path}/{id}"
204+
shutil.copyfile(file_path, f"{blob_path}/{object_name}")
205+
body["storagePath"] = f"local://{blob_path}"
204206
return self.post_request(f"{endpoint}/{id}", body=body)

0 commit comments

Comments
 (0)