ionic-framework - 如何使用后端 PHP 在 ionic 4/5 中上传图像?
问题描述
我想上传一张图片,为此,我的后端开发人员给了我邮递员的 JSON 演示,他要求将图片添加为 Multipart 表单数据。
首先,正如他所说的多部分表单数据,所以我像这个代码一样发送给他,但现在他说不是这个。
这是我的邮递员个人资料更新屏幕
上面的图像图像键头像和值是个人资料图片。请帮我...
解决方案
async uploadImageData(formData: FormData) {
const loading = await this.loadingController.create({
message: 'Uploading image...',
});
await loading.present();
this.http.post("http://localhost:8888/upload.php", formData)
.pipe(
finalize(() => {
loading.dismiss();
})
)
.subscribe(res => {
if (res['success']) {
this.presentToast('File upload complete.')
} else {
this.presentToast('File upload failed.')
}
});
}
这是上传代码,完整代码来自此参考: https ://devdactic.com/ionic-4-image-upload-storage/
推荐阅读
- python - 在 pandas 数据框列的一个列表中查找项目,但不在另一个列表中查找项目
- java - 旋转的 ViewPager 很难滑动
- r - 如何在分类变量的不同级别上运行配对 t 检验?
- javascript - JavaScript dom.style.display 根本不起作用
- jquery-ui - JqueryUI portlet 未加载(有时)。.
- python - Qt 访问 ExtraSelection 格式(测试)
- regex - 在 notepad++ 中使用 RegEx 解析字符串
- azure - 请求缩略图时来自 https://southcentralus1-mediap.svc.ms/ 的 503.2 错误过多
- python - 使用 tf.distribute.MirroredStrategy() 时无法加载 tensorflow keras 检查点
- c++ - 无法插入到集合中