Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to stream http request to file (handle big file uploading)? #5996

Closed
devalexqt opened this issue May 31, 2020 · 2 comments
Closed

Comments

@devalexqt
Copy link

How to handle big (~1GB) file uploading? In node.js/express we do it like this:

var stream=fs.createWriteStream(...)

stream.on("finish",()=>{
console.log("==>upload finished!")
})

req.pipe(stream)

But how do this in Deno?

@lucacasonato
Copy link
Member

The req.body property is a reader that can be used with Deno.copy to copy into a file:

import { serve } from 'https://deno.land/std@0.54.0/http/server.ts';
const s = serve({ port: 8000 });
console.log('http://localhost:8000/');
for await (const req of s) {
  const file = await Deno.create('f.txt');
  await Deno.copy(req.body, file);
  req.respond({ body: 'Hello World\n' });
}

@ry
Copy link
Member

ry commented Jun 1, 2020

As Luca wrote. Please reopen if that doesn't work for you.

@ry ry closed this as completed Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants