Warp: Question: pipe a request body into a file?

Created on 1 Mar 2019  路  1Comment  路  Source: seanmonstar/warp

I am coming from the Node.js world but I'm looking for something with low latency, type-safety etc.

For my use-case I want to pipe a request body into a file (upload). Is this possible in Warp, without having the full contents in memory?

feature

Most helpful comment

It is possible. You can get the request body as a stream via warp::body::stream(). And you can get an asynchronous-looking File with tokio-fs. Then you could combine Stream::for_each and tokio::io::write_all to write each chunk to the file. I'm on mobile, but I could later write up what that code looks like.

It does sound like very useful functionality to have directly in warp...

>All comments

It is possible. You can get the request body as a stream via warp::body::stream(). And you can get an asynchronous-looking File with tokio-fs. Then you could combine Stream::for_each and tokio::io::write_all to write each chunk to the file. I'm on mobile, but I could later write up what that code looks like.

It does sound like very useful functionality to have directly in warp...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevensonmt picture stevensonmt  路  5Comments

dylanede picture dylanede  路  3Comments

alexreg picture alexreg  路  7Comments

clintnetwork picture clintnetwork  路  3Comments

dpc picture dpc  路  7Comments