使用cordova文件传输通过https上传文件


Uploading file over https with cordova filetransfer

我在文件传输插件上遇到了一个问题,似乎无法解决。当我使用http时,我的代码可以工作,但当我尝试通过https上传时,它似乎没有将参数发送到我的api,但它确实到达了我的api。只有文件丢失,x-session-toke标头存在并且有效。这是我上传文件时使用的代码:

$scope.options = {};
$scope.options.fileKey = "file";
$scope.options.fileName = $scope.img.substr($scope.img.lastIndexOf('/') + 1);
$scope.options.mimeType = "image/jpeg";
$scope.options.headers = {
    'x-session-token' : window.localStorage.auth
}; 
// parameters: source, filePath, options
$cordovaFile.uploadFile("https:/****/api.php/profielpic/", $scope.img, $scope.options, true).then(function(result) {
  console.log(result);
  $cordovaToast.showShortTop('Uploaden gelukt!').then(function(success) {
    $ionicLoading.hide();
    $state.go('tab.profiel');
  }, function (error) {
    $ionicLoading.hide();
    $state.go('tab.profiel');
  });
}, function(err) {
  console.log(err);
  $ionicLoading.hide();
});

这是我在服务器端使用的代码,看看是否有什么:

$app->post('/profielpic/', function () use ($app) {
$auth           = new api'src'Auth;
$users          = new api'src'Users;
$authdata       = json_decode($app->request->headers->get('x-session-token'));
$data           = json_decode($app->request->getBody());
$userid         = $authdata->userID ;
$session_token  = $authdata->session_token;
$userdata       = $data->userdata;
$alertsarray    = array();
$message        = null;
$isValid        = true;
$authresult     = $auth->authenticate($userid, $session_token);
$imgname = time();
print_r(json_encode($authdata));
print_r(json_encode($_FILES));
print_r(json_encode($_POST));
print_r(json_encode($data));
print_r(json_encode(file_get_contents("php://input")));
/*
if($authresult === true) {
    $res = $users->updateUserPicture($userid, $_FILES['file']);
    if($res === false) {
        $isValid = false;
        $message = "Er ging iets mis.";
    }else{
        $message = $res;
    }
}else { 
    $isValid = true;
    $message = $authresult; 
}*/
$dataArray = array(
    'isValid' => $isValid,
    'message' => $message
);
echo ")]}','n".json_encode($dataArray);

});

但是所有东西都是空的https://如果我上传到http://它工作

有人知道为什么http有效但https不起作用吗?https不起作用的唯一情况是文件上传。我的其余api路由使用https。

它发生在iOS设备和Android设备上,所以问题更可能出现在瘦api上,我想

Api响应:

{
    "bytesSent": 32889,
    "responseCode": 200,
    "response": "{'"userID'":'"2'",'"session_token'":'"****"
} {'
    "file'":{'"name'":'"modified.jpg?1427448587960'",'"type'":'"image''/jpeg'",'"tmp_name'":'"''/tmp''/phpABKyF2'",'"error'":0,'"size'":37491}}[]null'"'")]}','n{'"isValid'":true,'"message'":null}",
    "objectId": ""
}

请确保您使用的是有效的SSL证书。如果您的应用程序正在访问API但未发送数据,则很可能您的应用已意识到连接不安全。它只会在与可以信任的服务器建立安全连接后发送数据。

自签名证书将不受信任。