Repository navigation
feat(core): open dropped and pasted files from their URLs - #297
Merged
Merged
Conversation
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 ".".
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.
I added |
houko
marked this pull request as ready for review
November 16, 2026 04:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 acore.FileforFile.Open:file:URLs: percent escapes decoded; on Windows/C:/names a drive (with no host orlocalhost) and any other host a UNC share (file://server/share/x,file://localhost/C$/x); elsewhere onlylocalhostmay 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 theFileeach drop made a URL for, so the result has the browser's size, type and modification time and reads theBloba slice at a time, as picked files do. Ablob:URL the page made otherwise is fetched when opened. Off the web, ablob: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.View.OnFileDropnow says the web givesblob:URLs;ReadClipboardFiles,PasteEvent,chat.Composer.OnDropFiles, the interaction architecture document and the public services guide (en, zh) point toFileFromURL.Notes
The branch no longer carries the CI and gallery timing commits of #274; they stay in that PR.
Verification
go build ./...;go vetof 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, andgo tool nsgo test -run 'Layer|Skills|Doc' ..go tool nsgo test -target web ./internal/platform/web: the newTestBlobFileReadsDroppedAndFetchedBlobsruns in a headless browser; it fails without the drop registry (size 0, no time).nsgo build -target web, in headless Chromium, received a synthetic drop of two files and opened them throughFileFromURLinsideOnFileDrop: names (notes #1.md), browser types, sizes, times and contents all matched, with no stall reading on the engine's goroutine.file:///C:/...,file://localhost/C:/..., and the UNC sharesfile://localhost/C$/...andfile://127.0.0.1/C$/...; a folder and a missing file returned errors.file:URLs go through the same path parsing the tests cover. Not checked on a device.Fixes #295