哈比:如何发送图像

我有一个JPEG图像二进制文件,我怎样才能使用Hapi来显示图像? 我的代码只显示垃圾给API的最终用户。

hapiServer.route({ method: 'GET', path:'/users/{userId}/photo', handler: async function (request, reply) { const userId = parseInt(encodeURIComponent(request.params.userId)); const photo = getImageBinary(userId); reply(photo); } }); 

假设你的图片二进制数据是png

 hapiServer.route({ method: 'GET', path:'/users/{userId}/photo', handler: async function (request, reply) { const userId = parseInt(encodeURIComponent(request.params.userId)); const photo = getImageBinary(userId); reply(photo).header('Content-Disposition','inline').header('Content-type','image/png'); } });