当我使用以下方法将相机/图像文件从设备上传到API时,我只想使用离子插件https://github.com/silkimen/cordova-plugin-advanced-http#uploadFile。
但是,根据下面注释的文档,它没有任何语法错误。
这个问题与参数有关,我不知道为什么...
错误:advanced-http:“ params”选项必须为字典样式 对象,
将图像上传到api的方法。
async uploadToAPI(imgEntry) {
var url = environment.api_host + "/activities/log/images"
var filePath = imgEntry.localURL;
var name = 'reports';
var body = {
user_hash: 'xxxxxxx',
activities_id: 1,
activities_log_id: 1
}
var headers = {
'Authorization': 'Bearer ' + environment.api_security_bearer
}
// (method) HTTP.uploadFile(url: string, body: any, headers: any, filePath: string | string[], name: string | string[]): Promise<any>
// @param url — The url to send the request to
// @param body — The body of the request
// @param headers — The headers to set for this request
// @param filePath — The local path(s) of the file(s) to upload
// @param name — The name(s) of the parameter to pass the file(s) along as
// @returns — returns a FileEntry promise that will resolve on success, and reject on failure
this.http.uploadFile(
url,
body,
headers,
filePath,
name,
).then((data) => {
console.log(data)
})
.catch(error => {
console.log(error)
})
}
上面的以下代码可能会由于错误而遗漏什么?
PS:仅,想使用ionic-native / http / ngx,没有其他用途。
import { HTTP } from '@ionic-native/http/ngx';
我向原始作者报告了github仓库,但后来我找到了一种解决方法,仍然使用ionic-native/http/ngx