使用图像响应本机发布请求

发布于 2025-01-14 14:07:36 字数 1122 浏览 1 评论 0原文

我在这件事上被困了好几天,所以如果有人好心帮助我,我就会来这里。我的问题是,当我使用 fetch 将图像发布到我的数据库时,我的身体使用图像选择器获取图像的表单数据,它只是给了我返回值(请注意,当我只使用 google chrome 来测试 .php 时,它工作得很好):


  <form method="POST" action="" enctype="multipart/form-data">
      <input type="file" name="fileToUpload" value=""/>

      <div>
          <button type="submit" name="fileToUpload">UPLOAD</button>
        </div>
  </form>
</div>

我的图像获取:

   console.log( NewImg)
      const data = new FormData();
      const url = 'https://jaimeleshommes.online/pub.php?Token=' + await AsyncStorage.getItem('TokenProfile')
       data.append("name", 'fileToUpload');
       data.append("file_attachment", NewImg.base64);
      fetch(url,
        {
          method: 'POST',
          body: data,
          headers: {
            'Content-Type': 'multipart/form-data; ',
          },
        })
         .then((response) => response.text())
         .then((ResponseData) => {
           console.log(ResponseData)
       });   

当我将“NewImg.base64”更改为“NewImg”时,我刚刚收到网络错误...非常感谢

I'm stuck for days on that, so i come here if someone has the kindess to help me. My probleme is that when I use fetch to post an image to my database with my body taking a formdata of my image with an image picker, it just gave me back that (Note that when i just use google chrome to test the .php , it work well) :


  <form method="POST" action="" enctype="multipart/form-data">
      <input type="file" name="fileToUpload" value=""/>

      <div>
          <button type="submit" name="fileToUpload">UPLOAD</button>
        </div>
  </form>
</div>

My fetch with the image :

   console.log( NewImg)
      const data = new FormData();
      const url = 'https://jaimeleshommes.online/pub.php?Token=' + await AsyncStorage.getItem('TokenProfile')
       data.append("name", 'fileToUpload');
       data.append("file_attachment", NewImg.base64);
      fetch(url,
        {
          method: 'POST',
          body: data,
          headers: {
            'Content-Type': 'multipart/form-data; ',
          },
        })
         .then((response) => response.text())
         .then((ResponseData) => {
           console.log(ResponseData)
       });   

When i just change 'NewImg.base64' to 'NewImg', I just got Network error... Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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