Skip to content

feat(core): open dropped and pasted files from their URLs - #297

Merged
houko merged 1 commit into
mainfrom
feat/file-url
Nov 16, 2026
Merged

houko merged 1 commit into
mainfrom
feat/file-url

Conversation

@houko

@houko houko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

File drops and clipboard reads hand apps URLs, not files: file: URLs on desktops and in pastes, and on the web, which hides paths, blob: URLs with the file's name as the fragment. Every app had to parse them itself, Windows drive and UNC paths included, and on the web had no way to get a dropped file's size, type or time from its URL. The gallery's chat composer showed . as the name of a file dropped on the web.

Change

Add core.FileFromURL, which turns such a URL into a core.File for File.Open:

  • file: URLs: percent escapes decoded; on Windows /C:/ names a drive (with no host or localhost) and any other host a UNC share (file://server/share/x, file://localhost/C$/x); elsewhere only localhost may be the host. The file is stat'ed for its size and modification time, its type comes from its extension, and a folder or a missing file is an error.
  • blob: URLs on the web: the backend now remembers the File each drop made a URL for, so the result has the browser's size, type and modification time and reads the Blob a slice at a time, as picked files do. A blob: URL the page made otherwise is fetched when opened. Off the web, a blob: URL is an error rather than a file that fails to open. Names that are not plain file names (empty, ., .., containing a slash) are refused.
  • Docs: View.OnFileDrop now says the web gives blob: URLs; ReadClipboardFiles, PasteEvent, chat.Composer.OnDropFiles, the interaction architecture document and the public services guide (en, zh) point to FileFromURL.
  • The gallery's chat composer names dropped files with the helper the file-drop demo already uses, so a file dropped on the web shows its name.

Notes

The branch no longer carries the CI and gallery timing commits of #274; they stay in that PR.

Verification

  • go build ./...; go vet of the touched packages for windows, linux, android/arm64 and js/wasm; go tool nsgo check -target all.
  • go tool nsgo test ./core, ./internal/driver, ./ui/chat, ./examples/gallery, and go tool nsgo test -run 'Layer|Skills|Doc' ..
  • go tool nsgo test -target web ./internal/platform/web: the new TestBlobFileReadsDroppedAndFetchedBlobs runs in a headless browser; it fails without the drop registry (size 0, no time).
  • Web, end to end: a probe app built with nsgo build -target web, in headless Chromium, received a synthetic drop of two files and opened them through FileFromURL inside OnFileDrop: names (notes #1.md), browser types, sizes, times and contents all matched, with no stall reading on the engine's goroutine.
  • Windows 11: the core tests cross-compiled and run on the machine pass, and a probe opened the same file through file:///C:/..., file://localhost/C:/..., and the UNC shares file://localhost/C$/... and file://127.0.0.1/C$/...; a folder and a missing file returned errors.
  • Linux (Ubuntu 24.04) and macOS: the core tests pass.
  • iOS and Android: no platform code changed; their clipboard file: URLs go through the same path parsing the tests cover. Not checked on a device.

Fixes #295

@github-actions github-actions Bot added documentation Improvements or additions to documentation Web core size/M enhancement New feature or request macOS iOS Windows Linux cli ci labels Nov 15, 2026
@github-actions github-actions Bot added the ui label Nov 16, 2026
@houko houko changed the title feat(core): restore files from drop URLs feat(core): open dropped and pasted files from their URLs Nov 16, 2026
Add core.FileFromURL, which turns the file: URLs that OnFileDrop, ReadClipboardFiles and pastes give, and the web's blob: URLs, into a core.File. On Windows a /C:/ path names a drive and a host a UNC share, localhost's admin shares included; elsewhere only localhost may be the host. The web backend keeps the File each drop made a blob: URL for, so the result has the browser's size, type and time and reads the Blob a slice at a time; another blob: URL is fetched when opened, and off the web a blob: URL is an error.

The docs say OnFileDrop gives blob: URLs on the web and point to the helper, and the gallery's chat composer names a file dropped on the web by its fragment instead of ".".
@houko

houko commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. I read the full diff against main and the Acceptance list of #295, rebased the branch onto current main (one commit, no conflicts) and re-ran the checks.

  • Code: filePath inverts what each backend writes: macOS and Linux build url.URL{Scheme: "file", Path: p}, iOS uses absoluteString, and Windows' fileURL writes file:///C:/... for drives and file://host/share/... for UNC paths, including \\localhost\C$. On the web, droppedURL keys the File by the URL without its fragment, which is exactly what blobFileFromURL passes back ("blob:" + u.Opaque), and reads go through the same blobReader as picked files. CHANGELOG.md is untouched, the touched comments are not hard-wrapped, and nothing unrelated is in the branch.
  • The tests catch regressions: making localhost always local on Windows fails TestFileFromURLPaths (file://localhost/C$/... and file:////server/...), and skipping the drop lookup fails TestBlobFileReadsDroppedAndFetchedBlobs (size 0, no time).
  • Builds: go build ./... for the host, windows and linux, android/arm64 for ./core ./internal/..., js/wasm vet of core, the web backend and the driver, and go tool nsgo check -target all.
  • Tests (macOS, headless): go tool nsgo test on core (545 passed), internal/driver (118), ui/chat (28) and examples/gallery (95 passed, 12 skipped).
  • Web: go tool nsgo test -target web ./internal/platform/web in headless Chrome, 7 passed, 1 skipped, the new blob test included.
  • Windows 11 (real machine): the FileFromURL tests pass, and a probe opened a real file named résumé #1.txt in a folder with a space through file:///C:/..., file://localhost/C:/..., file://localhost/C$/... and file://127.0.0.1/C$/..., with the right path, size, type, time and contents. A folder and a missing file gave errors, and so did a blob: URL off the web. Four other core tests (TestServicesGoThroughTheGate, TestGateRules and two DevTools commit tests) fail there when the test binary runs directly, without nsgo test, and they fail the same way on main's binary.
  • Linux (Ubuntu 24.04 VM): the FileFromURL tests pass.
  • iOS and Android: no platform code changed, and their file: URLs go through the path parsing covered above. I did not check them on a device.

I added Fixes #295 to the description.

@houko
houko marked this pull request as ready for review November 16, 2026 04:59
@houko
houko merged commit 7470b0f into main Nov 16, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OnFileDrop and ReadClipboardFiles give file: and blob: URLs, but nothing turns one back into a path or a core.File

1 participant