Meteor - writing image content to the browser from server -
i have server method makes api call contents of image file.
getimageapi: function (param1, param2, imagetype) { var url = http:/somehost/image?param1=' + param1 + '¶m2=' + param2 + '&imagetype=' + imagetype; var response = meteor.http.call('get', url, { headers: {"content-type": "image/jpeg"}, responsetype: "buffer" }); if (response.statuscode == 200) { return new uint8array(pdfresponse.content); } else { throw new meteor.error(pdfresponse.statuscode); return ""; } return ""; }
the parameter imagetype can have values such jped, tiff, raw, png etc..
the server side route calling method , writing content window.
router.route('/image', function () { var param = queryparam; var param1 = param.param1; var imagetype = param.imagetype; var param2 = param.param2; var content=""; meteor.call('getimageapi', param1, param2, imagetype, function (error, result) { if (error) { console.log("error occurred on receiving data"); content = ""; } else content = new buffer(result); }); } this.response.writeheader('200', { 'content-type': 'image/jpeg', }); this.response.write(content); this.response.end(); } }, {where: 'server'});
if specify content-type "image/jpeg" in response, shows broken image on window. if not specify content-type downloads .tiff file no matter type of image api returns.
i wanted know missing. while returning data server method (conversion buffer , uint8array)? or on server route (content-header , other header parameters) ?
Comments
Post a Comment