Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2024 11:59 AM
Hey Husky,
You can provide just the path to the file to upload with REST Api call. https://docs.databricks.com/api/workspace/files/upload. Its in Public Preview. Please see below.
def return_ws_url():
workspace_url = dbutils.notebook.entry_point.getDbutils().notebook().getContext().tags().get("browserHostName")
match = re.match(r'Some\((.*)\)', str(workspace_url))
if match:
value = match.group(1)
return(value)
else:
print("No value found")
def upload_ws_file_to_volume(local_path, remote_path):
with open(local_path, 'rb') as f:
r = requests.put(
'https://{databricks_instance}/api/2.0/fs/files{path}'.format(
databricks_instance=return_ws_url(), path=remote_path),
headers=headers,
data=f)
r.raise_for_status()
headers = {'Authorization' : 'Bearer {}'.format(dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get())}
print(headers)
upload_ws_file_to_volume(<<Your source file local path>>, <<UC Volume path>>)