【发布时间】:2021-04-11 02:55:22
【问题描述】:
我正在使用相机和图像选择器插件来添加使用相机和图库添加照片的功能。但是,当我从图库中选择图像并尝试发送到服务器时,作为 base64 图像,我无法将其发送到服务器端。它发送一个空字符串。
add.dog.ts.
//Open image picker multiple images
openImagePicker(){
let options = {
maximumImagesCount: 3,
}
this.photos = new Array<string>();
this.imagePicker.getPictures(options)
.then((results) => {
this.reduceImages(results).then(() => {
for (let index = 0; index < results.length; index++) {
this.photos.push(results[index]);
this.base64.encodeFile(results[index]).then((base64File: string) => {
this.pic = base64File;
this.authService.uploadPhotosServer(this.pic).then((result) => {
this.responseData = result;
}, (err) => {
console.log(err);
});
}
//console.log("Image Lists", this.photos);
});
}, (err) => { console.log(err) });
}
所以我在这里将this.pic = base64File 发送到我正在向这样的服务器发送发布请求的服务。
uploadPhotosServer(photos){ //console.log(photos);
return new Promise((resolve, reject) => {
let headers = new Headers();
let datafile = photos;
this.http.post(uploadDogPhotosGalleryAuthEndPoint,datafile, {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
resolve(err.json());
});
});
}
服务器端我正在尝试访问以下数据:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<pre>";print_r($_REQUEST);die;
}
但它总是打印为空。如果我检查控制台,它会显示请求有效负载,例如:
data:image/*;charset=utf-8;base64,/9j/4AAQSkZJRg
可能是什么问题?
谢谢
【问题讨论】: