Searched through the Overflow to see if I can spot a solution to this issue, but unfortunately nothing seems to be specific enough.
通过溢出搜索,看看我是否能找到解决这个问题的方法,但遗憾的是,似乎没有什么特别的。
I'm building an Ionic app with a photo upload feature (using the cordova-filetransfer plugin), and have an API endpoint set up to receive the image. The Ionic JS is able to process the image successfully, but the API responds back with the "disallowed keys" error; only it's full of random garbled nonsense.
我正在构建一个带有照片上传功能的Ionic应用程序(使用cordova-filetransfer插件),并设置了一个API端点来接收图像。 Ionic JS能够成功处理图像,但API会响应“不允许的密钥”错误;只有它充满随机乱码的废话。
The clean_input
function:
clean_input函数:
public function clean_input_keys($str)
{
$chars = PCRE_UNICODE_PROPERTIES ? '\pL' : 'a-zA-Z';
if ( ! preg_match('#^['.$chars.'0-9:_.-]++$#uD', $str))
{
exit('Disallowed key characters in global data: '.$str."\n [GLOBAL vars] \n".Kohana::debug($GLOBALS));
}
return $str;
}
The full response:
完整回复:
Disallowed key characters in global data: '()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚâãäåæçèéêòóôõö÷øùúÿÛ
[GLOBAL vars]
<pre>array: </pre>
The uploadImage
function from the mobile app:
来自移动应用的uploadImage函数:
$scope.uploadImage = function(datetime) {
// Destination URL
var uploadUrl = "url/goes/here";
// File for Upload
var imagePath = $scope.urlForImage($scope.image);
console.log('Path: '+imagePath);
// File name only
var filename = $scope.addZero(datetime.getDate()) + $scope.addZero((datetime.getMonth() + 1)) + datetime.getFullYear() + '-' + $scope.addZero(datetime.getHours()) + $scope.addZero(datetime.getMinutes()) + '-' + $scope.incidentData.store + '-' + $scope.incidentData.location + '.jpg';
filename = filename.replace(/\s+/g, '');
console.log('Filename: '+filename);
var success = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
};
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("Upload error source " + error.source);
console.log("Upload error target " + error.target);
};
var options = new FileUploadOptions();
options.fileKey = "image";
options.fileName = filename;
options.chunkedMode = false
//mimeType: "multipart/form-data",
options.mimeType = "image/jpeg";
var params = {};
params.fileName = filename;
options.params = params;
var headers = {
"API-Key": "keygoeshere",
"Content-Type": "application/x-www-form-urlencoded"
};
options.headers = headers;
var ft = new FileTransfer();
ft.upload(imagePath, uploadUrl, success, fail, options);
}
And the API endpoint function:
和API端点功能:
public function upload_image()
{
$this->authorise();
$file_temp = $_FILES['image']['tmp_name'];
$file_name = $_FILES['image']['name'];
$target_path = 'path/goes/here';
if (move_uploaded_file($file_temp, $target_path.$file_name)) {
Kohana::log('debug', 'File received: '.$_FILES['image']['name']);
Kohana::log_save();
} else {
Kohana::log('debug', 'Photo upload failed');
Kohana::log_save();
}
}
Sorry if this is a bit too much code, but I cannot work out for the life of me where this error is stemming from - any advice?
对不起,如果这有点太多的代码,但我无法解决这个错误源于我的生活 - 任何建议?
1 个解决方案
#1
1
The issue turned out to be the headers: I was posting a header (Content-Type) that the plugin already sends by default; the two were *ing and causing the error.
问题原来是标题:我发布的插件(Content-Type)默认情况下插件已经发送;两人发生冲突并导致错误。
Removing this header, leaving only the API-Key, has allowed the image to be sent.
删除此标题,只保留API-Key,允许发送图像。
#1
1
The issue turned out to be the headers: I was posting a header (Content-Type) that the plugin already sends by default; the two were *ing and causing the error.
问题原来是标题:我发布的插件(Content-Type)默认情况下插件已经发送;两人发生冲突并导致错误。
Removing this header, leaving only the API-Key, has allowed the image to be sent.
删除此标题,只保留API-Key,允许发送图像。