Add extra params to $cordovaFileTransfer.upload

可紊 提交于 2019-12-11 03:46:58

问题


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.


回答1:


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)



回答2:


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
 };



回答3:


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.




回答4:


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;


来源:https://stackoverflow.com/questions/32618984/add-extra-params-to-cordovafiletransfer-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!