Hi @lauraxyz here is an example using the Databricks SDK in Python:
from databricks.sdk import WorkspaceClient
ws = WorkspaceClient()
image_path = '/Volumes/catalog/schema/volume/filename.jpg'
image_data = (
ws.files.download(image_path) # download file
.contents # pull out streamed response
.read() # materialize bytes
)
From here, you can do whatever you like with the image bytes. For example:
from PIL import Image
from io import BytesIO
image = Image.open(BytesIO(image_data)) # open the image with pillow
image.show() #
If using a different language, we can always use the REST API directly, here is a quick Javascript example that uses the REST API (/api/2.0/fs/files):
// Set up API endpoint and headers
const host = "https://..."; // Replace with your workspace URL, leaving the end slash off
const token = "dapi..."; // Replace with your actual Databricks access token
const imagePath = '/Volumes/catalog/schema/volume/filename.jpg';
// Download image using REST API
fetch(`${host}/api/2.0/fs/files${imagePath}`, {
headers: {
'Authorization': `Bearer ${token}`
}
})
.then(response => response.blob())
.then(blob => {
const img = document.createElement('img');
img.src=URL.createObjectURL(blob);
document.body.appendChild(img);
})
.catch(error => console.error('Error:', error));