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;