使用图像响应本机发布请求
我在这件事上被困了好几天,所以如果有人好心帮助我,我就会来这里。我的问题是,当我使用 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 技术交流群。

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