Cordova FileTransfer not sending custom headers

1.3k views Asked by At

I try to send custom header with cordova FileTransfert but when i check in PHP the function getAllHeader(), 'i not find my custom header.

var options = new FileUploadOptions();
options.fileKey = "picture";
options.fileName = imageData.substr(imageData.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";

var headers={'headerParam':'headerValue'};

options.headers = headers;

var ft = new FileTransfer();
ft.upload(imageData, url, succesFileTransfer, errorFileTransfer, options);

In PHP i check the headers with : getallheaders(); and i do not find the header sended previously.

Thank you for your help

1

There are 1 answers

0
Pixelight On BEST ANSWER

Php doesn't show headers posted via Cordova FileTransfert. I think that header sent is protected.

The header can be captured in PHP via this portion of code :

$this->header = getallheaders();
$this->uid = (isset($this->header['uid']) && !empty($this->header['uid'])?$this->header['uid']:null);

echo $this->uid; //return the User Id sent via Post request from Cordova FileTransfert.

Hope this help someone