【发布时间】:2018-07-15 10:36:00
【问题描述】:
我想就 Node / Express 中的 REST API 向您寻求帮助。
我正在调用供应商 API 以获取 PDF 格式的标签,然后我需要将其发送给正在调用 API 的用户。
我正在使用request npm 包调用另一个 API。我也尝试过node-fetch,但没有成功。
示例代码:
retrieveLabel(req, res, next) {
const options = {
method: 'GET',
url: 'apiUrl' + 'shipments/xxx/label',
headers: {
'cache-control': 'no-cache',
authorization: xxxToken,
'content-type': 'application/json'
}
};
request(options, (error, response, results) => {
// NO idea how to send it as reponse...
});
}
在控制台中有字符串类型的响应,以这样的开头:
%PDF-1.4
%����
3 0 obj
<
</Type /XObject /Subtype /Image /Width 1171 /Height 1676 /ColorSpace /DeviceRGB /BitsPerComponent 8 /Decode [0 1 0 1 0 1] /Interpolate false /Filter /FlateDecode /DecodeParms<
</Predictor 12 /Colors 3 /Columns 1171 >>
/Length 61782 >>
stream
X���o�]�}'�;!Yl"�ɠh����x�H&�r�h�@(�3[ҋHK"�r+)K�q{kYL���fl���H�)��@�By�v�Ԭ\Z��3�-�5�Զ*PEJ���EU�����G�Ϲ�v���t��S��n���s�sn��>�y���1y��y��r'��Nrȝ��;�
wݓ�Ν;�m��b�X,��b�X,s�D �MO?�܊,6@rK&''w����b���266�H�%��_~��r�C���X,�e�K��������U��۲e���%+�������|���*��?pr �@�$7��In���r'��Nrȝ�0���o���|עʑ#Gn�������u�s��Z���ɓqe��|U >��9z�%�ٳw
....
【问题讨论】:
标签: node.js api express stream