离子上传错误:Advanced-http:“ params”选项必须是字典样式的对象,

问题描述 投票:0回答:1

当我使用以下方法将相机/图像文件从设备上传到API时,我只想使用离子插件https://github.com/silkimen/cordova-plugin-advanced-http#uploadFile

但是,根据下面注释的文档,它没有任何语法错误。

这个问题与参数有关,我不知道为什么...

错误:advanced-http:“ params”选项必须为字典样式 对象,

enter image description here

将图像上传到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';
javascript cordova ionic-framework cordova-plugins cordova-plugin-advanced-http
1个回答
0
投票

我向原始作者报告了github仓库,但后来我找到了一种解决方法,仍然使用ionic-native/http/ngx

© www.soinside.com 2019 - 2024. All rights reserved.