Okay so your advice worked somewhat, turns out the issues was my XMLHttpRequest was not fully forging a correct POST request.
I decided to stay with a Base64 image and just send it to the server as such, the request is sent through a proxy server so i could sniff the global headers.
Here is the output:
(i know that 'pretty' is not an API field but it has significance for the usage of the pretty printer that i used to filter the text so that i dont flood your comments with a massive block of Base64 code)
[CODE title="Request Outout"]-------------------------------------------------
--- BEGIN REPORT --------------------------------
-------------------------------------------------
GET ---------------------------------------------
Results From _GET array
-------------------------------------------------
POST --------------------------------------------
Results From _POST array
* key --> [Redacted Per NDA with employer]
* source --> iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAQx0lEQVR4nO2dzY4kRxWFu7q6q6vGVcMI[Truncated For Pretty Print]
* pretty --> true
* format --> json
-------------------------------------------------
REQUEST -----------------------------------------
Results From _REQUEST array
* key --> [Redacted Per NDA with employer]
* source --> iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAQx0lEQVR4nO2dzY4kRxWFu7q6q6vGVcMI[Truncated For Pretty Print]
* pretty --> true
* format --> json
-------------------------------------------------
SERVER ------------------------------------------
Results From _SERVER array
* HTTP_HOST --> 192.168.1.101
* HTTP_CONNECTION --> keep-alive
* CONTENT_LENGTH --> 6206
* HTTP_ACCEPT --> */*
* HTTP_ORIGIN --> file://
* HTTP_USER_AGENT --> Mozilla/5.0 (Linux; Android 8.0.0; SM-S757BL Build/R16NW; wv) AppleWebKit/537.36[Concantated For Pretty Print]
* CONTENT_TYPE --> application/x-www-form-urlencoded; charset=UTF-8[Truncated For Pretty Print]
* HTTP_ACCEPT_ENCODING --> gzip, deflate
* HTTP_ACCEPT_LANGUAGE --> en-US,en;q=0.9
* HTTP_X_REQUESTED_WITH --> com.piccastle.mobile
* PATH --> Z:\.sys\miniperl\bin;Z:\.sys\php;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\[Concantated For Pretty Print]
* SystemRoot --> C:\WINDOWS
* COMSPEC --> C:\WINDOWS\system32\cmd.exe
* PATHEXT --> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC[Truncated For Pretty Print]
* WINDIR --> C:\WINDOWS
* SERVER_SIGNATURE -->
* SERVER_SOFTWARE --> Apache/2.4.3 (Win64)
* SERVER_NAME --> 192.168.1.101
* SERVER_ADDR --> 192.168.1.101
* SERVER_PORT --> 80
* REMOTE_ADDR --> 192.168.1.145
* DOCUMENT_ROOT --> Z:/web
* REQUEST_SCHEME --> http
* CONTEXT_PREFIX -->
* CONTEXT_DOCUMENT_ROOT --> Z:/web
* SERVER_ADMIN --> admin@localhost
* SCRIPT_FILENAME --> Z:/web/test/test.php
* REMOTE_PORT --> 37177
* GATEWAY_INTERFACE --> CGI/1.1
* SERVER_PROTOCOL --> HTTP/1.1
* REQUEST_METHOD --> POST
* QUERY_STRING -->
* REQUEST_URI --> /test/test.php
* SCRIPT_NAME --> /test/test.php
* PHP_SELF --> /test/test.php
* REQUEST_TIME_FLOAT --> 1560324049.248
* REQUEST_TIME --> 1560324049
-------------------------------------------------
- EOF -------------------------------------------
-------------------------------------------------[/CODE]
Note that the Content Type is
Code:
application/x-www-form-urlencoded
, that is because when the
is set, i got no entries in the header.
Im wondering if the data is not being correctly sent to the server in a meaningful way, namely the API key seems to be invalid, but when i cURL it with my terminal, the key works just fine. So the key is correct.
Here is my upload code:
JavaScript:
function upload(){
if(currentBase64Image != " " && currentBase64Image != ""){
//============================================================================================================
var CUSTOMER_ENDPOINT = "https://piccastle.com/api/1/upload/";
//var LOCAL_ENDPOINT = "http://192.168.1.101/test/test.php";
$.ajaxSetup({
// DOES NOT WORK. PHP server returns all vars as unset.
//contentType: "multipart/form-data; boundary=!XIS"
});
var jqueryXHR = $.post(LOCAL_ENDPOINT,{
key: getApiKey(),
source: currentBase64Image.split(",")[1], // Removing the header info from the image, as to send the RAW image with no META
//pretty: "true", // TEST SERVER VAR
format: "json"
},function(data,status){
// Success
if(isJSONValid(data['responseText'])){
// Response is JSON
var json = JSON.parse(data['responseText']);
if(window.ismodules["ISNotification"] && window.ismodules["Color"]){
new ISNotification(GREEN,"Image Upload Successful",SECOND * 5,BOTTOM).show();
}
}else{
// Response is probably text.
if(window.ismodules["ISNotification"] && window.ismodules["Color"]){
new ISNotification(YELLOW,data,SECOND * 5,BOTTOM).show();
}
}
console.log(data);
});
jqueryXHR.fail(function(data){
if(isJSONValid(data['responseText'])){
// Response is JSON
var json = JSON.parse(data['responseText']);
if(window.ismodules["ISNotification"] && window.ismodules["Color"]){
var msg = json["error"]["message"];
var rest = json["status_txt"];
new ISNotification(RED,rest + ", " + msg,SECOND * 5,BOTTOM).show();
}
}else{
// Response is probably text.
if(window.ismodules["ISNotification"] && window.ismodules["Color"]){
new ISNotification(RED,"Error: " + data,SECOND * 5,BOTTOM).show();
}
}
console.log(data);
});
}
}
EDIT:
Hope you can help
🙂 and as far as i can see there is not any url corruption as a result of the content type, i think that only occurs when sent via the URI, but this data is sent in the request body, and seems to match, in other words, it matches and is binary equivalent to the source, so it has to be how i make requests.