I have a code block like this. I am getting data with this Function.
cloudApi.jsx file:
export const fileApi = axios.create({
baseURL: cloud_url,
headers: {
"Content-Type": "application/json",
CLIENTID: clientID,
CLIENTACCESSKEY: clientAccessKey,
CLIENTSECRETKEY: clientsecretKey,
},
credentials: 'include'
});
export const FileService = {
async getFile(path) {
try {
const response = await fileApi.get(path);
return response.data;
} catch (error) {
console.log("error", error);
}
},
};
And this is Logo.jsx file:
const [imageSrc, setImageSrc] = useState("");
const getFile = async () => {
try {
const path = "src/assets/icons/googleIcon.png";
const response = await FileService.getFile(path);
console.log("response", response);
setImageSrc(response);
} catch (error) {
console.error(error);
}
}
useEffect(() => {
getFile();
}, []);
and Response give me a data below;
Result:
�PNG
IHDR00W�� pHYs���IDATx��oLeǟ{Zz�-F��a�?����2
��ű��4�f�c��
�1(�A q&6덻:\�ڍ�"�7�C��N�sm�UH��٣eI���]����]��O���?($���b(�,�{�M� J� @*HC6�&A���:T�� _4R����6a�$��$,�ƷA�}�:Y8��,�)�YS@1���x � ��c�=��p�Э�y�������=< ��ߍ�~���I���h~��8����N4x���=x,2��D�ୱOB%��&i PhP(�HނӘr�6��8[�M��7�!�AXy�����Y|@�g���*�R��oT����/��p�(x�y��������| @��<z$A-&u&����t���ߐ�z$�l~Y��Q�
��IX���6b�$�_�T��I�9������0ɴN�:���6j�L^q)�u�/X3b4\;a;��w���s)������u��<t#�+��5��|�@�}%��z�j��U߂����0_ ��=��Q��L���F;}%pD7<�C@v�I��g�����^�DN�p��菾��(��8�^�T8����CW���{Il��������{@̲{K�63 �X8d;��ͣ����_�&|[�zgd��� ��Z���(~O��D6��7m��L�2��V�&/p\�Ǐ)��i�l���/ik��=)p�/��:�)�R?ff<��8J���3�v�������XA�70�W�+�D���[���ވ�^�U����Xs���=�J>���ȧ��ί�P�)rw��Emjg����֜�8����J}zJЗ�r�٘�,+EX�t�q/�g#\�t��2�J�h�SW�$L�_�rL�H�P���;��7u#O�c��
xҢ�r�Y}g��M?"O��G�4t�}oH~Q��&|z������tp|b8n�s5L�7$��sA�za��~���,?+dM���c�Fc�����3F5�2��_yC����iF��0�'����zǐ�1x��Î�~�ƫ���34���Ud8�X(x��������|k�$�g�[��F�L��j:mQePZ�w�~�5d�Ԇ�Ūk��-�~��S�����i��%g ']IEND�B`�
I want to display this response image data in img object but I don't know how I can do that.
<img className="logo" src={mainLogo} alt="PNG Image" />
I try this code but it didn't work.
const getFile = async () => {
try {
const path = "src/assets/icons/googleIcon.png";
const response = await FileService.getFile(path);
setImageSrc(`data:image/png;base64, ${response}`);
} catch (error) {
console.error(error);
}
}