Quantcast
Viewing latest article 14
Browse Latest Browse All 42

streaming a remote image to the buffer using Koa

First time playing around with nodejs streams.. I feel like I'm missing something fundamental here about how streams work. When I make the request to the URL it logs out a 404. If I try to write to the buffer it throws an error.TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object

  1 const Koa = require('koa')  2 const app = new Koa()  3 const fs = require('fs')  4   5 const url = 'http://4.bp.blogspot.com/-cDeYCsNL-ZQ/UozsUJ7EqfI/AAAAAAAAGSk/EtuzOVpHoS0/s400/andy.png'  6 app.use(ctx => {  7   const buffer = new Buffer.alloc(1000)  8   ctx.request.get(url).pipe(fs.createWriteStream(buffer))  9   console.log(ctx.request) 10   console.log(ctx.response) 11 }) 12  13 app.listen(1337)

Viewing latest article 14
Browse Latest Browse All 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>