【发布时间】:2020-03-02 10:28:10
【问题描述】:
在我的应用程序中,我有 cordova camera 插件,它允许我拍照并从中获取 URI。
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
this.camera.getPicture(options).then(
imageURI => {
},
err => {
}
);
然后我使用该 URI 上传到我的服务器。
this.http
.uploadFile(
'https://example.com/pages/attachments.php, {
action: 'INSERT'
}, {},
'file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1583144250046.jpg',
'picture'
)
.then(
fileResult => {
console.log(fileResult);
},
err => {
}
);
但是我从console.log 结果中得到了这些错误:
未定义索引:文件在第 1235 行
未定义的索引:文件在第 1236 行
这些是attachments.php中的行:
// The tmp_name is the name of the temporary file on the server.
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$_FILES 似乎是空的,但我不知道为什么。我假设使用http.uploadFile 会发送文件,但我不确定为什么不是。有什么帮助吗?
【问题讨论】:
标签: ionic-framework file-upload cordova-plugin-advanced-http