NodeJS axios调用API结果与AWS s3 bucket链接不正确

qpgpyjmq  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(82)

所以基本上,我有两个API服务,比如service1和service2。
在基于expressJS构建的service1上,代码如下:

const fetchDocument = catchAsync(async (req, res) => {
  const data = await getDocument();

  if (!data) throw new ApiError(httpStatus.NOT_FOUND, 'Document not found');

  res.status(httpStatus.OK).send({
    url: 'https://test-test-certificate.s3.ap-southeast-1.amazonaws.com/folder1/folder2/certificate.pdf?AWSAccessKeyId=111111111&Expires=1690870068&Signature=Mo7SHci8hCIPxfd7qBJmfcGDBg6%2Fgs5A%3D&x-amz-security-token=IQoJb3zJpZ2fdluX2VjEDbYaDmFwjyLXNvdgXRoZWFzdC0xIkcwRQIgd%2Fn12w8uaCdyAdn1fawQrW%2BeVPV%2BE3X3O6VsIB8t2NsCIQCpXYO%2BtECX8btUg7tYGO0Y2xZqLCMQ0b%2Facr7lfrCq1CqkBQjP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAEaDDMwNDA2MjI3NzY3MCIMxyvFJ9%2Br9UjctAOOKvgETfwpgPv%2BWkSZOB8aazQ%2FtDzu%2FcnMtBxV9QHPjncEbhN95fDlo50sS5qogTSU6Ayy4FgN4%2F%2FXmrpAHPNfCVICnrblOj%2FnmlPL9zbaR0Xnbhzs3hDX%2FaJhpLRaebwazN8JcE7S0On9siDisS4%2BvuGsEPedFit3gcX9JxsRENOWDfW1eHTFxPQ3AQclecPWbqlqLAySQrJ4Dy3Zpjnnbrl4flFNYFdrz2xwYyk2K1KQSEvkq127hIM356CXw7r47iCTx6O1i5LsswuDlIVl0gAwkpiVmpIq8fOIGtu4JtMFtli%2BETc73XgZStQsOElG30LdMF2Yi1yXbjNQR9DwwqFHsil06MjFhaNufwoe%2FoXzMEEI6tJ5qJ79QC5h7WE%2Bur0f0c9v9VwjFW1%2B4GBtKasMl7ql%2BqoQmABXBUDmagtTmBAll8ywlFKAYTkwozRBdRhZyXflhut8hZpLCPN7yGNKLqrXhb6QHmXgwVKMBekraxwfRkmGVrhLcSxdssUxnzF4Po3q9ElR0Puh%2FmkMSjvGd8I9APrHi0RBWwGzJ%2BeUZ%2B08ARokrPsah2pbieh2A7OKybSBCnhbZeXWfLyujvnfuhyLMD4tDasM%2FYMREMGKLcQaGaRIV3Xx24mxaAUzD2NLIdYyb%2FNEK3fPP0wlcDkI4Sb6eMGHQ3LsreMrmXiySoLXmhrsUO8rtugKgMH5C9xXP6ZZYXIBcDbptK9Pes6kT291l%2BUbr9%2BfIHlxf6YnMm5cYmmIC3XWbZrVU%2B8vmmONY7mAQ1BtsMneKQxe548qiCnmKWmzns1X1bvcDcKdXkVPHwKK7O2Bp9gAwvgGEX8ltO57Bq6whHIwiMCipgY6mwF%2FpI6q2kTXjSGZ44qkJiBNbJs3eCTbkV46F%2FVbHt2wdNdDBxgl%2B0RnoqEEVYP0biC%2Fhd%2BIzHFuZvnles8Db5hmMFHplUFRALpQMFo0tSVuC0UO2%2BmsngigrkBMTV7m7b1EHfB6H5YUJpGf9vztDwbdqUvWUkAhzWIb%2ByP%2FAR6kTK70znCpGiqLAC1N0IxiWEKBxGa6V%2FITXTAlEQ%3D%3D'
  });
});

字符串
当我通过postman执行这个命令时,我得到了预期的结果,这是在硬编码的“url”键对象上给出的。
然而,当我使用axios在service2内部调用这个API端点时,我得到了这样的结果:

�\b\n}�׮�8@����7߫h,�-+K��ߔ%+����#cf�\u000bH�X8���?d1���p|/��]���jxI��E��0�d��\u000b�_�x��<��~�]|\f}���t辳!]�����_�F1� �I����/��5f�����4@�w5��y*�0=B�����wG�_�6�s~��04�P�/�.�.s��h�Z3���=�.UD����% ����k���qy��5�/ph����\f���O�]B�Ib������Bwx�\tȦ6��:j����Vf��l�-�ՙ�����n���g fAu�1���JB�$�Q�0R,$¶�\u000b��$'4Ng�-faB��᝗}���0��I�(�)r��Rq�pCP�m�7�|nf�r���K�^�ci�Ou�xO�g��pN����ހ����~���T&Kb;�\b��i(�ރ����K��ǁ��G�j���B?'�����km�=��E�>��Wb���V����&sK%�C���X�$��E��gr\r�2\r��\\ɴ�\b��z�7��9'm�����tn���F�;�_}��-Q����|`��\r����I�fB1�R\r���p�g����FYhM���ت~���ڌ�ߍ�������AC�m���=��|z���*8�g��E5����t\\V\\�I���E(�%W��됟��aH�J�9�h�Ȋ����H����ח���Px���h�=���t���Kx�x�m�}me����:.���s��Z S=G]�MzWLM��J(�څ��k�7s����t�?Wz�m��?d����Z�����k\f��V2Fe9{�ֈ��r�>��<W��ܡ�mWؘ�y�q����\u000b}�<�0(�}y��b�v�\t(�1���p%C��ԉ��U}<�0��b�q����Y���4��mdmS�Q\t/�rC�:��ܘ��޽A�j���Rj�q%v\u000bm���B�O�d�k�j��~��H�OO��\n*ꍎL��S<\f���?�K��u���<F�kΖ�3�B�iAw�\r�䝊����o_WM�-�����KE\n�Z$�O�Z]յ6�z,#�[?-3�Ԅ5���)O���[͛�\r�pO��>6~r�ؚ���o��q��I���F�Z8-�s��q���os��\tYu�|ۇ�r���@�_�aa�q��.�7�>��\t*]\u000b�����6*�>��&��x����@=���Ĺg59zaT���Dԭ$�ߔ�:睬��;�J�9bO���ߪ�r�X


而不是我所期待的链接,这里发生了什么,如何修复它?
下面是我在Axios上的代码:

async getDocument() {
    try {
      const data = await axios.get('localhost:4000/documents');

      console.log('XXXXXXXXXXXX', data);
      return data;
    } catch (error) {
      logger.error(error);
    }
  }

atmip9wb

atmip9wb1#

已经解决了,这是我的解决方案呵呵

async getDocument() {
    try {
      const data = await axios.get('localhost:4000/documents', {
      responseType: 'json',
    });

      console.log('XXXXXXXXXXXX', data);
      return data;
    } catch (error) {
      logger.error(error);
    }
  }

字符串

相关问题