I’m trying make file upload using $cordovaFileTransfer. When I add params to send to the webservice the params doesn’t send and I don’t know why. I made my webservice with CakePHP.
How could I solve this ?
Controller
/** add image profile */
function addImagemUsuario(){
var img = document.getElementById('smallimage');
var _pathFile = img.src;
var _fileName = _pathFile.substr(_pathFile.lastIndexOf('/') + 1);
var _url = AppConstants.webServiceUrl + "/users/addImageUsuarioApp.json";
var _headers2 = HeaderProvider2.getHeader();
//options
var options = new FileUploadOptions();
options.chunkedMode = true;
options.mimeType = 'image/jpg';
options.fileKey = 'imageFile';
options.headers = _headers2;
options.fileName = _fileName;
//params
var params = new Object();
params.idUsuario = 333;
params.imageFile = _fileName;
options.params = params;
$cordovaFileTransfer.upload(_url, _pathFile, options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
}, function (err) {
console.log("ERROR: " + JSON.stringify(err));
}, function (progress) {
// PROGRESS HANDLING GOES HERE
});
};
CakePHP webservice
public function addImageUsuarioApp(){
$this->autoRender = false;
$id = $this->request->data["idUsuario"];
$retorno = array("id"=>$id);
return json_encode($retorno);
}
Exception
<pre class=\"cake-error\"><a href=\"javascript:void(0);\" onclick=\"document.getElementById('cakeErr56528e8dd2bcb-trace').style.display = (document.getElementById('cakeErr56528e8dd2bcb-trace').style.display == 'none' ? '' : 'none');\"><b>Notice</b> (8)</a>: Undefined index: idUsuario [<b>APP\\Controller\\UsersController.php</b>, line <b>200</b>]<div id=\"cakeErr56528e8dd2bcb-trace\" class=\"cake-stack-trace\" style=\"display: none;\"><a href=\"javascript:void(0);\" onclick=\"document.getElementById('cakeErr56528e8dd2bcb-code').style.display = (document.getElementById('cakeErr56528e8dd2bcb-code').style.display == 'none' ? '' : 'none')\">Code</a> <a href=\"javascript:void(0);\" onclick=\"document.getElementById('cakeErr56528e8dd2bcb-context').style.display = (document.getElementById('cakeErr56528e8dd2bcb-context').style.display == 'none' ? '' : 'none')\">Context</a><pre id=\"cakeErr56528e8dd2bcb-code\" class=\"cake-code-dump\" style=\"display: none;\"><code><span style=\"color: #000000\"><span style=\"color: #0000BB\"> </span><span style=\"color: #007700\">public function </span><span style=\"color: #0000BB\">addImageUsuarioApp</span><span style=\"color: #007700\">(){\r</span></span></code>\n<code><span style=\"color: #000000\"><span style=\"color: #0000BB\"> $this</span><span style=\"color: #007700\">-></span><span style=\"color: #0000BB\">autoRender </span><span style=\"color: #007700\">= </span><span style=\"color: #0000BB\">false</span><span style=\"color: #007700\">; \r</span></span></code>\n<span class=\"code-highlight\"><code><span style=\"color: #000000\"><span style=\"color: #0000BB\"> $id </span><span style=\"color: #007700\">= </span><span style=\"color: #0000BB\">$this</span><span style=\"color: #007700\">-></span><span style=\"color: #0000BB\">request</span><span style=\"color: #007700\">-></span><span style=\"color: #0000BB\">data</span><span style=\"color: #007700\">[</span><span style=\"color: #DD0000\">\"idUsuario\"</span><span style=\"color: #007700\">];\r</span></span></code></span></pre><pre class=\"stack-trace\">UsersController::addImageUsuarioApp() - APP\\Controller\\UsersController.php, line 200\nReflectionMethod::invokeArgs() - [internal], line ??\nController::invokeAction() - CORE\\Cake\\Controller\\Controller.php, line 490\nDispatcher::_invoke() - CORE\\Cake\\Routing\\Dispatcher.php, line 193\nDispatcher::dispatch() - CORE\\Cake\\Routing\\Dispatcher.php, line 167\n[main] - APP\\webroot\\index.php, line 115</pre></div></pre>{\"id\":null}"