【发布时间】:2018-08-31 18:27:53
【问题描述】:
我尝试将多张图片从 ionic3 上传到 serverur php,但出现错误图片未发送到后端。我使用 imagepicker 插件选择多张图片..
代码角度:
testfile(){
for (var l of this.images)
{
if(l !== 'K' && l !== 'O')
{
this.base64.encodeFile(l).then((base64File: string) => {
var formData = new FormData();
formData.append('photo',base64File);
this.http.post('url api',formData, {responseType: 'text'}).subscribe(res =>
alert(res),
err => {
this.presentToast(err);
});
}
, (err) => {
this.presentToast(err);
this.presentToast('error encode');
});
}
}
}
我也尝试发送 base64File 而不附加到 formData 并且我尝试发送 l(进入循环)但在所有情况下都会出错
【问题讨论】:
-
描述错误并更新更多代码...
-
任何错误但返回的响应是空数组而不是对象文件
-
imagepicker 插件给我们base64 字符串.....为什么你需要这个.. 图像数组发送到服务器不需要一张一张地发送图像
-
@Utpaul ,我尝试不使用 this.base64.encodeFile 但也有错误:(
标签: angular cordova typescript ionic-framework ionic3