-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Not working with Base64 #70
Comments
I do not really get what's your issue, what's that you're doing in order for that error to pop up? |
The image that im fetching from the API is not an image url but a Base64 string. example:
|
I meant what's the code you wrote for it to fail like this. |
I was referring to this example: https://glazzes.github.io/react-native-zoom-toolkit/components/resumablezoom.html To be more specific, here's my whole code: import {
View,
Text,
Alert,
Image,
ActivityIndicator,
useWindowDimensions,
} from "react-native";
import React, { useState } from "react";
import CustomButton from "@/components/CustomButton";
import { useSingleSession } from "@/store/kvmSessionStore";
import getVncScreenshot from "@/actions/getVncScreenshot";
import {
getAspectRatioSize,
ResumableZoom,
useImageResolution,
} from "react-native-zoom-toolkit";
export default function Vnc() {
const [loadingData, setLoadingData] = useState(false);
const [screenshot, setScreenshot] = useState<VncScreenshotProps | null>(null);
const { singleSession } = useSingleSession();
const getScreenshot = async () => {
setLoadingData(true);
try {
const sceenshotResponse = await getVncScreenshot(
singleSession as KvmParams
);
setScreenshot(sceenshotResponse);
} catch (error) {
console.log("Getting Screenshot Error", error);
Alert.alert("Error!", error?.toString());
} finally {
setLoadingData(false);
}
};
const { width } = useWindowDimensions();
// Gets the resolution of your image
const { isFetching, resolution } = useImageResolution({
uri: screenshot?.data!,
});
if (isFetching || resolution === undefined) {
return null;
}
// An utility function to get the size without compromising the aspect ratio
const imageSize = getAspectRatioSize({
aspectRatio: resolution.width / resolution.height,
width: width,
});
return (
<View>
<Text>Vnc</Text>
<CustomButton onPress={getScreenshot}>
{loadingData ? (
<ActivityIndicator color='#fff' />
) : (
<Text className='text-white'>Get Screenshot</Text>
)}
</CustomButton>
<View className='items-center justify-center w-full h-80'>
{loadingData ? (
<ActivityIndicator color='#F96002' />
) : (
<ResumableZoom maxScale={resolution}>
<Image
source={{ uri: screenshot?.data }}
// style={{ height: "100%", width: "100%" }}
style={imageSize}
resizeMode='contain'
resizeMethod='scale'
/>
</ResumableZoom>
)}
</View>
</View>
);
} where
|
Did you even check the validity of that base64 image? I've tried with an image I converted online to base64 and passed it to useImageResolution hook and everything worked fine for me, I tried the base64 string you passed to me and it does not work. |
I'm closing the issue as it's clearly not related to the library, I tried on both platforms and no of them proved to be related to your problem, by the looks of the of error logs it's a problem with the base64 image data being interpreted as a null value, see a similar issue |
@Glazzes you shouldn't hurry on closing the issues. Github closes them automatically if no activity. I wasn't home so i couldn't reply that fast. But when i use it with your library i get that error. Probably is not your library's issue whatsoever, however for now i gave up on this functionality. I will get back to this when i have more time. |
@IlirBajrami My bad and sorry for the hurry, I just made several tests to render images with a base64 string by passing strings, null and undefined, same to the function that gets the resolution of an image, nothing proved to cause the issue you have, you could make some testing with RN Image's import {Image} from 'react-native';
Image.getSize('base64 image', (w,h) => console.log(w, h), () => console.log('failed')); |
Summary
My source is a Base64 image and i get this error when trying to load it:
Environment
Steps to Reproduce
No response
The text was updated successfully, but these errors were encountered: