Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid base64 string from Ruby controller

All I want to do is respond with a base64 string when this action on my controller is contactacted.

class V1::AppProxyController < ApplicationController

  def logo
    send_file("#{Rails.root}/public/fresh_modal.png", 
              type: "image/png", 
              disposition: "inline")
  end

But the response, when I put it into an online converter, does not return the image. Plus it has all those odd characters. What am I doing wrong?

"�PNG


IHDRZ
�*tEXtSoftwareAdobe ImageReadyq�e< iTXtXML:com.adobe.xmp<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00        "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CS5 Windows" xmpMM:InstanceID="xmp.iid:56A07D6E335911E7B92CC44F92F10C15" xmpMM:DocumentID="xmp.did:56A07D6F335911E7B92CC44F92F10C15"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:56A07D6C335911E7B92CC44F92F10C15" stRef:documentID="xmp.did:56A07D6D335911E7B92CC44F92F10C15"/> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>&���IDATx��Yy�]U��]�6�7K;��L�^���(aS*�����(U�H��A!`E�
Fb�&P ����S�Bי��v��0�[�g���w�yCJĶ�5��{������߹t�i�ȥA��U-�ќ%2$袙��9¥���vl��*Pu��fd�G�C�h�vn����ς�$��K����"q(?��$��˒�ȥ��%8�s^�4���h�  r�C[�'|�v�1)#��D������#���x�w�MO��
��C�����Q�H���y�������:�ʣ듮�pF��=��.RZ���?��t��'�Y�%����kZ#���|�&�wOx�B��N���љ�EȓG!��/�j�Q��̄c�q�j���gj�u�Չ��^��Z�%�T�q�S&��v��
i�l;
�A��>��#J�Ԁ��Kr���3^e��Q
 �2�u�(�
�H.�ڕ�ۑ�kѿQ�}2��"H�%$�!\n� wC��9�<kmyзX��:.�L��w��}��*���e�O�T[�ӣ�G�кCfֶ'#�����`p%�
5f��Q,���9�@������.Wb�{ E�x;~�dp+��07Ɇ��m�Z��D�b0<  :'�&���a��I���Z��zkM ������ wA.��
� �5����:�Bf�ޞ��y�-rVxal*!��+�s����v�|ځ�j��GÖ9ў<�Ga�єt(���bd���c;,�l���u���� � i�A{��Z�N��
M�����[�+>�{�ju�?N��y�Qu�Ċ��kv���Ha �S%!/@�Cx��G�����}Eu�"���!������(�mD��[�T���O��N��;v!�N�-�g"���Ӎ5r�}Wm�
�����.x�-�{-��ހ
���a�?#��.7J���7�~Zs�`jhS�J��ϋ��1��C�k��v�&�No]ek�lA\j��~pEz��)�r��؉����T&.x�>�   i����HRG^S�Ly
y: �2h�u8��Upj!j����x���D�(]�q�'6�6���\�����H|v䜊s+�r/dnٺn�Cx��x�����Y�w:R!i-��Z���W�~�vl���[(�ߣR��i�}���h[    "���n���8�;�{�W�]B�R�>�l�\9'��m�Cu�V���G��(=
W=6ӓm���
Қ��z�oH�Q����ꅢ
�!�,r���t��Tq�"�-thQ�F��h+�g�|���[8 �b���ƹ�
��k��z��Z�݌�sh�/��e�1YfD�
hJ���x����J9?���I)>B?]�Ov�TA"��B�|/��$�q�δ�cC�v�Խ��� ��ja�;�Q�㺫�R��\���z?�Xi�H��+)��m���獪��~�mU���wUT�V�2x=RBeh�V�&��KE�F���u��L4��P�fv������3Fw[�]*��N�    o���}��hq�,���kVa�F<6�8�A��AQ~�o��FF4���s�&8T1d��X*�(�6^��Ps�w�����@C���0R�z1M"�z�GUQDSD)I?��W)�N�}�a����:1�44}�~��2*��\o5�a�>�7�x�-����8�<�   mĻ�޹Ɩ�!���=�FG�����0������N�x��#!�t��C��w��M�;�JQ��2Rt{��e�H�v�q>�H�@Ͳ��FQ�ݾcvH��y���J���>�5c�!�&��x����J0�lҥ9��r�
4���q ��r=��y�����t��p���Ә=�g�*�Z�:���XO�(�    ��Qm���nJ���P���{��0���D3-j�C[�|g#��n�#���V����h*����5����i�?d%�u�R��B�    ߉����h��fG���,h��,�;��.�U��oJ��I
�����8�!�����������t̒{16��S�0�]���P�i�Ci����H��Fd
=�K��,��+����m��y�w$������[�F�G=?���a8�=�J�ل��0J�\����c��ӡ�zk�G��_-ݟ����5�S+��G���/΃l��)<8��;��=\��M��2�K��V�%���؃��x�\g�|��ay+��B8�QEX,R��G��h�,R_�"Cf�,���j�LFDbic#�v5��
G}rQ��:+]�_���P�b�>�L^*�X����LD��8DE��'Γ&>?
"����0<2gL:��YuL����|��"�
 7��~����Ɇ]]vY��Ts7�w8�\x�Dl�Ur<��eU~���)���g��&E7���n�On@�>��q�X+r��ZN��s�κ8DCj
G��HKن+�N�tg�V�Y�)_ڿc�-�r��3��5��B?���1`zvILa�Y���0v������k�=��ډ��(J�&������W@:{�[?�?�]�+[�����H�k�!�<�vf;��x�ڢ��&��-J��ǠÆE�"�+�5�4�^�yl   ���b�*��a�Ɠ�B����
i�!�����i�:����b����c��@�j��p$�����:->�}הNǓE)�h9�OB�e��Ü�3��腦��\S5ca�ɘ,�p�C�C��T8���nK���X6L���c?� �r���B-���i>�*�ǁ��͂�����W
_l��ȳ[ૻ��W6Sh���@��I����<��6�H{%2A��g��60��.��A��m0J?t'`�<�a,,m�x>��q�K[Z>   Z���'��.��y��5�M�� #ĝ�JₔSe��g����J��VtQ�^
��AyU�O�R[`FV*�U���d�A��K�a�S�����h�Gڑ���Y�?�б.�c)�1��~�_ƙ(S���IEND�B`�"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to encode the file to Base64 instead of returning the binary data

File.open("#{Rails.root}/public/fresh_modal.png", 'rb') do |img|
  base64_file = 'data:image/png;base64,' + Base64.strict_encode64(img.read)
end
render plain: base64_file
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading