i have a canvas where is stream video, i'm taking a snapshot of that and sending it to a server how do i know that i have sent the snapshot successfully to server ? i cant see anything in 'Preview' section and should my payload look like that ?. I can see the snapshot in front end using that img tag. status is :
and in payload getting:
and there is nothing in 'Preview'
const canvasRef = useRef(null);
const [preview, setPreview] = useState('');
const getImage = () => {
return new Promise((resolve) =>
canvasRef?.current.toBlob((blob) => {
const src = URL.createObjectURL(blob);
setPreview(src);
resolve(blob);
}),
);
};
const takeSnapshott = async () => {
let pollUrl = `api/cam/${first}/${second}/snap`;
const blob = await getImage();
// SEND THE BLOB TO YOUR SERVER
const formData = new FormData();
formData.append('file', blob, 'picture');
try {
const res = await fetch(pollUrl, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
body: formData,
});
const data = await res.text();
console.log('resso', data);
if (res.ok) console.log('SUCCESS', data);
else throw new Error(data);
} catch (e) {
console.error(e);
}
<img src={preview} style={{ width: '100%', height: 'auto' }} />