dify icon indicating copy to clipboard operation
dify copied to clipboard

File preview endpoints advertise `Accept-Ranges: bytes` but ignore `Range`, so seeking in audio/video re-downloads the whole file

Open cty-ut opened this issue 1 month ago • 0 comments

Self Checks

  • [x] I have read the Contributing Guide and Language Policy.
  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report, otherwise it will be closed.
  • [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.17.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Start Dify 1.17.1 with the default docker compose setup.
  2. Create a Workflow app. The Start node has a single-file input that allows video. The End node outputs that file. (No model is needed.)
  3. Run it with a ~10 MB MP4 (2 minutes, H.264, faststart), then open the output video.
  4. In Chrome DevTools → Network (cache disabled, filtered by file-preview), drag the progress bar to near the end a few times.

Request from the browser when seeking:

[

Image

]

Every response (first load and each seek) is 200 with the full file: Accept-Ranges: bytes is present, Content-Range is absent, and Content-Length is 10819023, the whole file.

[

Image

]

After a few seeks, Chrome has transferred 37.6 MB for a 10.8 MB file:

[

Image

]

To check the server directly (use a fresh signed URL from DevTools):

curl -s -D - -o /dev/null -H "Range: bytes=0-99" "<signed file-preview URL>" | grep -iE "^HTTP|accept-ranges|content-range|content-length"

Expected: 206 with Content-Range: bytes 0-99/<size>. Actual: 200 with the full Content-Length.

✔️ Expected Behavior

Since the response advertises Accept-Ranges: bytes, a Range request should get 206 Partial Content with Content-Range and only the requested bytes. Seeking should then fetch only the part of the file it needs.

❌ Actual Behavior

The Range header is ignored. Every request returns 200 with the entire file. Playback and seeking still work in both browsers I tried, but they have to download much more than needed:

  • Chrome 155: each seek starts another full download. Chrome reads from byte 0 and discards data until it reaches the target position. In my test that was 6 requests and 37.6 MB transferred for a 10.8 MB video. seekable was [[0,120]] and buffered was [[0,104.418],[107.944,120]]. [
Image

]

  • Safari (desktop): the video plays and seeks. buffered was [[0,120]], meaning it fetched the whole file. [
Image

]

For small files this is barely noticeable. For large videos, slow connections, or object storage billed by egress, every seek costs a full-file transfer. I have not tested iOS.

Cause. Two endpoints set the header for audio/video MIME types but never look at Range:

  • api/controllers/files/upload_file_delivery.py:135-136 (/files/<file_id>/file-preview, used by the web players and tested above)
  • api/controllers/service_api/app/file_preview.py:151-152 (/v1/files/<file_id>/preview, same pattern)

Both stream storage.load_stream(key) from the start. BaseStorage (api/extensions/storage/base_storage.py) only offers load_once / load_stream, with no way to read from an offset.

History. #19116 asked to "include Accept-Ranges: bytes and support Range requests". #19119 added only the header, and later endpoints copied it.

Possible fixes (I'd like maintainers' preference before writing code):

  1. Add a ranged read to the storage interface (most backends, such as S3/OSS/GCS/Azure/local, support it natively) and return 206 from both endpoints. This is correct and efficient, but it touches every storage backend.
  2. Handle Range in the controller by skipping bytes from load_stream and returning 206 with the requested slice. This is a small change and protocol-correct, but the server still reads from the start of the file, so storage egress isn't reduced.
  3. Stop sending Accept-Ranges until ranges are supported. This is the smallest change and makes the response honest, but I haven't checked whether it makes browser seeking worse.

I'm happy to submit a PR for whichever approach you prefer.

cty-ut avatar Oct 16 '26 13:10 cty-ut