question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to stream files

See original GitHub issue

Hi, I am trying to stream files from local disc (for a reason it’s not served as static).

I tried to use sendStream or send it directly to pipe but each time I get 404. Documentation is not mentioning too much how to use streams. How to use it correctly with h3?

export default defineEventHandler((event) -> 
     const stream = fs.createReadStream(path);
     stream.pipe(event.res);
)

or

const stream = fs.createReadStream(path);
      sendStream(event, stream);

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
maciej-jezierskicommented, Apr 16, 2022

I found solution by using playground and checking code. Solution is super simple, sendStream has to be returned directly

const r = "/path/to/file
return sendStream(event, fs.createReadStream(r))

In my case if you have promise first it’s working as well

return $fetch(apiUrl, { method: "GET", parseResponse: JSON.parse }).
    .then(r => sendStream(event, fs.createReadStream(r.path)))

KISS, but generally would be good to add it to documentation before some other people run into this issue as streaming files is common exercise.

1reaction
pi0commented, Apr 17, 2022

@Atinux We should probably start adding examples directly to h3 docs. Otherwise, we will end up with fragmented documentation and outdated info for utils. Also, consider sendStream support is not universal yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stream (or sync) Drive files to users' computers - Google Help
To access Drive files and keep them in sync on all your devices, use Google Drive for desktop. This application lets you stream...
Read more >
How to stream large .mp4 files? - GeeksforGeeks
How to stream large .mp4 files? · Open terminal · mkdir <project name> · cd <project name> · npm init -y · Open...
Read more >
How to stream files from OBS | Videolinq Help Center
Click on the OBS "Settings" tab (lower right side) and enter the OBS stream configuration area. On the left navigation bar click on...
Read more >
How to stream local files to your Chromecast or Android TV
The first thing you want to do is download the app, Videostream. You can do that here. send files to your chromecast videostream...
Read more >
How to stream your personal video collection to any device
Fire up a Roku player, for example, load up the default media player, and you should see your files ready to be streamed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found