无法在控制台中查看发布请求图像
我有一个帆布在哪里流视频,我正在拍摄该快照,然后将其发送到服务器,我怎么知道我已经成功地将快照发送到了服务器?我看不到“预览”部分中的任何东西,我的有效载荷应该像那样吗?我可以使用该IMG标签看到前端的快照。 状态为:
和在有效载荷获取中:
,'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' }} />
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' }} />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论