Serve small text-based files inline instead of redirecting to S3#314
Serve small text-based files inline instead of redirecting to S3#314kabilar wants to merge 1 commit into
Conversation
Previously, GET requests for assets such as JSON, YAML, TSV, and other text-based files were redirected to S3, which serves them with an `application/octet-stream` content type, causing browsers to download them rather than display them inline. dandidav now fetches such files (when no larger than 10 MiB) and serves them itself with a browser-displayable content type: - JSON files (any `.json`, plus Zarr metadata `.zattrs`/`.zarray`/ `.zgroup`) as `application/json` - YAML files (`.yaml`/`.yml`) as `text/yaml` - Other text files (`.tsv`/`.csv`/`.md`/`.txt`/`.bidsignore`) as `text/plain` Larger files continue to be redirected to S3 as before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Hi @yarikoptic, for context I would like to be able to directly display text files (zarr.json, tsv, etc.) in the browser rather than downloading. I tested the functionality locally and it works, but I relied on claude to generate the code since I don't have much experience with rust. Thanks. |
|
Here is a dandiset with several of those file types (tsv, json, yaml, .bidsignore) that can be used for testing: https://webdav.dandiarchive.org/dandisets/001412/draft/ |
yarikoptic
left a comment
There was a problem hiding this comment.
I think it might be just a matter of providing extra url options like we do on dandiarchive.org already: e.g. on https://dandiarchive.org/dandiset/001412/draft/files?location= you can
- open in the browser -- https://api.dandiarchive.org/api/assets/7d298d77-4bca-4a3f-91e3-ab81b22ebd48/download?content_disposition=inline
- download -- https://api.dandiarchive.org/api/assets/7d298d77-4bca-4a3f-91e3-ab81b22ebd48/download/
so I would have just added that [view] or just 👁 which would have the URL with the URL with ?content_disposition=inline to the download API endpoint. Or am I missing the goal here?
|
Hi @yarikoptic, that's a good idea. Using |
|
sure -- as much as possible to centralize/formalize instead of ad-hoc solutions on webdav level. Here worth double checking (I forgot) how it is interacting with encodingFormat -- see discussion in elderly and potentially just give it current assessment etc. Related (might be addressed by working on this) |

Problem
GETrequests for assets such as.json,.yaml,.tsv,.md, and.bidsignorefiles are redirected to S3, which serves them with aContent-Type: application/octet-stream. Browsers download these files rather than displaying them inline.Fix
dandidavnow fetches small text-based files (≤ 10 MiB) itself and serves them with a browser-displayable content type instead of redirecting:.jsonfile, plus Zarr metadata files.zattrs/.zarray/.zgroup(which have no extension) — served asapplication/json.yaml/.yml— served astext/yaml, matching the virtualdandiset.yamlfiles.tsv/.csv/.md/.txt/.bidsignore— served astext/plain, which browsers reliably display inline (more specific types liketext/tab-separated-valuestend to be downloaded)Files larger than 10 MiB continue to be redirected to S3 as before, to avoid buffering large amounts of data in memory. This also covers Zarr entries served via both the Archive and the Zarr manifests.
In the HTML collection view, links for these files now point to dandidav's own path (rather than directly to the S3 download URL) so that clicking them displays the file inline.
Verification
inline_content_typeunit tests covering JSON / YAML / plain-text / Zarr-metadata / non-inline cases (case-insensitive extensions included)cargo test(367 passing),cargo clippy, andcargo fmt --checkall cleandandisets/001412:dataset_description.json→application/jsonand.bidsignore→text/plain, both200with noContent-Disposition(display inline), versus the current307→ S3 →application/octet-stream(download)🤖 Generated with Claude Code