我正在读取缓冲区数据,然后需要写入文件(图像),但是由于某些原因,我尝试打开文件时得到了
不支持的文件
app.post('/upload', function(request, respond) {
if (!fs.existsSync(os.tmpdir())){
fs.mkdirSync(os.tmpdir());
}
let body = '';
//const extention = request.query['ext'];
request.once('data', function(data) {
body += data;
console.log(body);
fs.writeFile('test.jpg', body, 'binary', function(err){});
/*const out = path.join(os.tmpdir(),'file.'+extention) ;
console.log(out);
fs.appendFileSync(out,body);
console.log(fs.existsSync(out));
getFile(out)
.then(x=> {respond.send(x)} );*/
});
});
我不想使用multer或其他任何东西,因为它们出于某种原因不能在云功能中使用。
我的身体:
Content-Disposition: form-data; name="data"; filename="man-workout-gym-working-wallpaper-preview (1).jpg"
Content-Type: image/jpeg
���� JFIF �� �
%%-))-969KKd
�/���'��@�w��m]�0��ȍ,I�+�t�b��c0Z�-��צ��- %c$! ����G��L�4��q7��N2N.��=܆CHƣ�������!���jfk��C�S����;A�]�c�����!`�z�s���*�LPIu��~��|�����w*6�08�m�l@����l,tL#d=���xa%��ƏW�֗��@�MU�� $��4h�`"p�P��Β:�S���#\0e����eNjq"�`�K3@���Τlc2�+�c�����������b��J�OX��lX��/I�.T��F,���h�'��eZW3����.�G-�(��Yd=$肻���j��2�Z̖�!�>t��N%fHm� <.�, �RfL,Efc��p��Z <s�1&-\�H��E'm(N0(X�ю;^ƕr����0g���\���^36h쉛,C�e�7p]�K�.Q���s˙�M���PI1v��4��p<��T�Ȁx]�b��@��
eۻNW����0`M��~�J�t�r:K\���cލ8����Y�6�Y)b%�N#0#%��rH4>���J���A���+��DŽ/Cf�M���!�+m�w�b-Yl�ng[�dݽ����}H�9MwWLL�\��F�\��j�W�C{3��ؘHQ�G�R�������|��f���4����i�����A�okխ�K��2M�oU��ۛ28hZ��D��_�r��g�n8�K�`����)�4z�n
��k���FY�t��ׄ��^fyfL"�M����@�fV�F ^��OD��(L�Y����>��A�y�ʽa��4��b ��e�F{��s�O�t1� L�&~~��Z�����!�v9Sؗ�J���"�s�ՠA�K-ON�>_Fڎ�J-���L��B��-�2
�(��V,Y��孧_/
c��6�����N ]g�K"�r/};�EԷ�Wxxj��l�n{p_S��ٿ9(��}aQ [�'�LrY ��@:�:�뚾��r�1n��X����YLs���c.J�vG���������+�����3e���Ďg>w����ޅ�J
@^��g�Z��x�|�"��(k5�q�lx�ݯ&Rڡ��^ �����e�LF&����'g������ձsă�eL�������-lVqn�����_ࣦ�6�r�I�¤�S��Bѫ�nk犷3f�Юx�����Qo��c��*"#ۉ#�T�����/�C���1��1��K����bY!@�I�Cy�F
u�W�rk�L��>>��`�wh�b�ڳ��Rk⻄jÀ�Yw�M=��;��[��;Y��K�K"��pN��3h�a9����%{v�[��)��[�y5�=��ݺH���d=9�
e�"�}�w�����J��vg8>j/���x:WGH��7K��[�LJB�d����S�H�C�Y{�49��
s�ԗ��H���|C�V�b�':��d,?B�^D��8��
˚�K/a/d#f�/#q��f3�a��Y`V�m����2�ݿ��� �Rv�&Q��¬;VQ A.���+dy�7�ݍ�=�y�h�d�2[���wÇ�]E���_�O����?66�W��Z#y���J�e3��!�-ry�;s��i��5#Ħc��W�U;��I�]Vʹ�b�ϭt!\so�ޓ̈�^���#������n:�������vu/\t
oF�,�!
缓冲区:
<Buffer 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 38 30 37 33 30 39 39 36 36 37 32 31 32 38 30 38 31 32 37 38 34 37 ... >