2016-11-15 79 views
0

通過溢出搜索以查看我是否能夠找到解決此問題的方法,但不幸的是,似乎沒有什麼特別的。「禁用全局數據中的關鍵字符」與Unicode垃圾

我正在用照片上傳功能(使用cordova-filetransfer插件)構建一個Ionic應用程序,並且設置了一個API端點來接收圖像。 Ionic JS能夠成功處理圖像,但是API響應「禁止鍵」錯誤;只有它充滿了亂七八糟的亂七八糟的廢話。

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; 
} 

全響應:

Disallowed key characters in global data: '()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÛ 
[GLOBAL vars] 
<pre>array: </pre> 

從移動應用的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); 
    } 

和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(); 
    } 
} 

對不起,如果這是有點太多的代碼,但我不能解決這個錯誤源於我的生活 - 任何建議?

回答

1

問題原來是標題:我發佈了插件默認發送的標題(Content-Type);兩人發生衝突並導致錯誤。

刪除此標頭,只留下API密鑰,允許發送圖像。