Add extra params to $cordovaFileTransfer.upload

2019-07-08 09:55发布

I am using $cordovaFileTransfer.upload() to upload a picture from a device to my server. In documentation it says that it excepts these params: server, filePath, options. I need to pass in some extra custom params: like user_id, for example. Does anyone know if it's possible to do? Thank you.

4条回答
唯我独甜
2楼-- · 2019-07-08 10:16

You need to use the 'params' property, like this:

var _options = {
    fileKey: "image_name",
    fileName: "image.jpg",
    chunkedMode: false,
    mimeType: "image/jpeg",
    httpMethod: "POST",
    headers: { },
    params: {
        "extra_param_name": "Jamilson",
        "extra_param_last_name": "Junior"
    }
};

Hope this helps.

查看更多
趁早两清
3楼-- · 2019-07-08 10:20

You can add "params" to options object, for example :

 var options = {
                fileKey: "name",
                fileName: "image.png",
                chunkedMode: false,
                mimeType: "image/png",
                httpMethod: "post",  //here the methed (get, post,..) 
                params: $scope.Data  //here you can submit the data
 };
查看更多
我想做一个坏孩纸
4楼-- · 2019-07-08 10:28

You can send those custom parameters in the options object, doing something like this:

var options = {};
options.headers = {
    Connection: "close"
}
options.chunkedMode = false;
options.userName = 'Mati';

$cordovaFileTransfer.upload(server, filePath, options)
查看更多
相关推荐>>
5楼-- · 2019-07-08 10:28
var options = new FileUploadOptions();
options.fileKey = "image";
options.fileName="image.jpg";
options.mimeType = "image/jpeg";
options.httpMethod="POST";
options.headers = {
    Connection: "close"
};
options.chunkedMode = false;
var params = {};
params.user_id ="123";
params.username="username";
options.params = params;
查看更多
登录 后发表回答