Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: s3 usage in mo.ui.file_browser() (#4457)

Myles Scolnick34434e532d5d
diff --git a/frontend/src/utils/pathUtils.test.ts b/frontend/src/utils/pathUtils.test.ts
index f03324b03f..b82c8b4e14 100644
--- a/frontend/src/utils/pathUtils.test.ts
+++ b/frontend/src/utils/pathUtils.test.ts
@@ -43,6 +43,26 @@ describe("getProtocolAndParentDirectories", () => {
]);
});
+ it("should handle S3 paths", () => {
+ const path = "s3://bucket/folder/subfolder/";
+ const delimiter = "/";
+ const initialPath = "s3://bucket/folder";
+ const restrictNavigation = true;
+
+ const { protocol, parentDirectories } = getProtocolAndParentDirectories(
+ path,
+ delimiter,
+ initialPath,
+ restrictNavigation,
+ );
+
+ expect(protocol).toBe("s3://");
+ expect(parentDirectories).toEqual([
+ "s3://bucket/folder/subfolder",
+ "s3://bucket/folder",
+ ]);
+ });
+
it("should handle paths without protocol", () => {
const path = "/folder/subfolder/";
const delimiter = "/";
diff --git a/frontend/src/utils/pathUtils.ts b/frontend/src/utils/pathUtils.ts
index e1572a72ba..559eb8665a 100644
--- a/frontend/src/utils/pathUtils.ts
+++ b/frontend/src/utils/pathUtils.ts
@@ -9,8 +9,8 @@ export function getProtocolAndParentDirectories(
initialPath: string,
restrictNavigation: boolean,
) {
- // Determine protocol (http://, gs://, C:\, or /)
- const protocolMatch = path.match(/^[A-Za-z]+:\/\//);
+ // Determine protocol (http://, gs://, C:\, s3://, or /)
+ const protocolMatch = path.match(/^[\dA-Za-z]+:\/\//);
const isWindowsPath = /^[A-Za-z]:\\/.test(path);
const protocol = protocolMatch
? protocolMatch[0]
diff --git a/marimo/_plugins/ui/_impl/file_browser.py b/marimo/_plugins/ui/_impl/file_browser.py
index 1889d8e7bf..6850ee84be 100644
--- a/marimo/_plugins/ui/_impl/file_browser.py
+++ b/marimo/_plugins/ui/_impl/file_browser.py
@@ -64,10 +64,10 @@ class file_browser(
)
# Access the selected file path(s):
- file_browser.path(index) # returns a Path object
+ file_browser.path(index=0) # returns a Path object
# Get name of selected file(s)
- file_browser.name(index)
+ file_browser.name(index=0)
```
Connecting to an S3 (or GCS, Azure) bucket:
@@ -79,10 +79,10 @@ class file_browser(
)
# Access the selected file path(s):
- file_browser.path(index) # returns a S3Path object
+ file_browser.path(index=0) # returns a S3Path object
# Read the contents of the selected file(s):
- file_browser.path(index).read_text()
+ file_browser.path(index=0).read_text()
```
Using with client credentials: