Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- useEffect(() => {
- const fetchData = async () => {
- try {
- const response = await fetch(`https://esb.optimalwayconsulting.com/fcbq/1/jR4rgA5K6Chhh5vyfrxo9wTScdg2NT7K/Federateds/getPhotobyUuidFederat/${player.uuid}`);
- const base64Response = await response.text();
- setImageUrl(base64Response);
- } catch (error) {
- console.error("Error al obtener la respuesta:", error);
- }
- };
- fetchData();
- }, [player.uuid]);
- useEffect(() => {
- // Decodificar la cadena Base64 a datos binarios
- const binaryData = atob(imageUrl);
- // Crear un Uint8Array a partir de los datos binarios
- const uint8Array = new Uint8Array([...binaryData].map(char => char.charCodeAt(0)));
- // Crear un Blob a partir del Uint8Array
- const blob = new Blob([uint8Array]);
- // Crear una URL de objeto a partir del Blob
- const imageUrlFromBlob = URL.createObjectURL(blob);
- // Hacer una solicitud fetch a la URL de la imagen para obtener la respuesta JSON
- fetch(imageUrlFromBlob)
- .then(response => response.json())
- .then(data => {
- // Extraer el valor de photoUrl de la respuesta JSON
- const photoUrl = data.messageData[0].photoUrl;
- setImageSrc(photoUrl);
- })
- .catch(error => {
- console.error("Error al obtener la respuesta JSON:", error);
- });
- // Limpiar la URL cuando el componente se desmonte
- return () => URL.revokeObjectURL(imageUrlFromBlob);
- }, [imageUrl]);
Add Comment
Please, Sign In to add comment