简体   繁体   English

使用 Node JS 处理传入的 JPEG 图像

[英]Handling an incoming JPEG image with Node JS

I am trying to get an imagen with a Post request using the library "request"我正在尝试使用库“请求”获取带有 Post 请求的图像

I get the image with a content-type: image/jpeg, which look as follows:我得到的图像内容类型为:image/jpeg,如下所示:

�PNG\r\n\n\rIHDR��\bL<�� IDATx��yxT���?���g2��!$$a�EP���-*j�ZkU�Vk-���\\j]Q���*�Zw�u�KqA@d��!�@BH�>�̝{���$�@��}&��s�3��=�y��+\\z�J� ��E��0\"'�����nr6�&�ʤmp!v��W����p��q���'� ͕�/�{�HM�om�z�?v���3>0º�V��z��U��:?���ǟ9���}C0�P�m�k��ּ7V?\b�ɧ�Hq�9ḣ�t?[?\t���5U$�Ԅ9�w�T�gg�C�zs3�G���\u000b۸쌡����F�7���QN�;{���V&��-C�54�d��\"2��ʨ35V�*��<���m|����M��vFo�Ywxa���F1�4��6�D�6������s��;�*xm��,��clnL�[����|�w7���g��هH��?��n��#x�y��_s�g�x������~�ɱ��v;���,��=ښ��������~y#����Y����������_|Γ�}�5g������_�����%x����3�b5--m?k:��~˪�\n��^��A��s�����{ú�?^�'�^{m����_��~�=�\\��nn��V�N'�P��\u000b2g��\r��E�8����Ł@*�|elZ��1�^��֪�H��GD����7�0bpb�՚�f�B\b5 jP�cQ�i�r��?���`�d�*��>�'�k۝�X���$\\XBĞ�<�F��#�/�SV�JQ��kg�Thh\r����;o,������F��i1�\r5�.m���/_\tc� �e\"�iĶE/k���b���\b<�^�����RR��ﯬ�ᤕ\t�Bed+�p{Gcud�}(����C�(�Kw��U�����pQ����W����EL,va�H�\n��V@П��\bJO�t9&�}U�<䁺�a*W&'ǃJ��<��j�F�A��EQH�N�ߗ�V�������@�b�]m�m���)���L��L�#�L�5Dehd+�w~QµLA?a�-�w\r\"sK�^���D뭚����Jp;# �\f*������fJ��1�x���@1f\\\\i�܂!�c�*DĄv��x2��*���q����+/�[0��W�I(�n����^���}�'�����l�,.��>�HI2��#s�ޑ;Qn�(�Eq�E2�a�;��Iٻ����m��\t�Ӊ(���vl6�P�H$¢E�8�3bd�p��\\jv��C� �W�[H��1\u000bc�RD�倉�&�Pl�Plq}��р�ވ�J|AD%44�vB՝�ۈ��i���aٸ*v�@Hr8�����K�c�w�c�`2��#j�ܭOl�����&y1�Q$��8�����RO(���\r��É���X����n5O�F+! fbV���� �ݝ=sP�X�W������,&�m�=��/x�^*j�:g���L��V\u000b�ur����Й��S`�4��X��K-\buy��F��fk\u000b/Rͨ�RlF��a\\�S�،�y��3ij�Փ�@�]���p���I�(���q�V��&����_N>��K~�f'��&...

Then, when I want to render it on an email template which is build with a template string, I don't find out how to put that image on it.然后,当我想在使用模板字符串构建的电子邮件模板上呈现它时,我不知道如何将图像放在上面。 I had found similar questions but this is always do in the client side.我发现了类似的问题,但这总是在客户端进行。

There are three approaches you could take.您可以采用三种方法。

In my order of preference (which happens to coincide with the best likely bandwidth costs):按照我的偏好顺序(恰好与最可能的带宽成本一致):

  1. Save it somewhere where it will have a public HTTP(S) URL, then use that URL in the email.将其保存在具有公共 HTTP(S) URL 的某个位置,然后在电子邮件中使用该 URL。
  2. Make it one of the parts of your multi-part MIME email (presumably, if you are dealing with HTML formatted emails you are already using multi-part MIME so you can have a plain text alternative since not doing so is a red flag for spam filters) and then use a cid: scheme URL to reference it.使其成为多部分 MIME 电子邮件的一部分(大概,如果您正在处理 HTML 格式的电子邮件,您已经在使用多部分 MIME,因此您可以使用纯文本替代方案,因为不这样做是垃圾邮件的危险信号过滤器),然后使用cid:方案 URL来引用它。
  3. Convert it to a base64 data: scheme URL and use that in the email.将其转换为base64 data:方案 URL并在电子邮件中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM