我有一个 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');
}
});
关于javascript - 哈皮 : How to send image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40504869/