Unable to serve image (png) with node.js and express -


i've studied similar questions on haven't found solution problem... i've set express route serve images can't return image it's stored. notice i've included statement allow requests origin. happens when make request http://localhost:8080/images/x10.png response empty image element src="http://localhost:8080/images/x10.png instead of http://ubuntubox.dev/images/x10.png, image located , path i'm passing request method. missing? thanks.

app.get('/images/*', function(req, res, path){   var imagepath = req.url,       url = 'http://ubuntubox.dev' + imagepath;    request(url, function(error, response, img) {     if(!error && response.statuscode === 200) {       res.header('access-control-allow-origin', '*');       res.writehead(200, {'content-type': 'image/png' });       res.end(img, 'binary');     } else if(response.statuscode === 404) {       res.status(404);       res.type('txt').send('oops');     }   }); }).listen(8080, '127.0.0.1'); 

i don't know if still have problem, but..

the solution problem putting .pipe(res) , send file response

app.get('/images/*', function(req, res, path){   var imagepath = req.url,       url = 'http://ubuntubox.dev' + imagepath;    request(url).pipe(res); }).listen(8080, '127.0.0.1'); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -