无法在控制台中查看发布请求图像

发布于 2025-01-20 17:12:17 字数 1942 浏览 0 评论 0原文

我有一个帆布在哪里流视频,我正在拍摄该快照,然后将其发送到服务器,我怎么知道我已经成功地将快照发送到了服务器?我看不到“预览”部分中的任何东西,我的有效载荷应该像那样吗?我可以使用该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 :

enter image description here

and in payload getting:

enter image description here

and there is nothing in 'Preview'

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文