I ended up not using API Express. I built an upload service to send the file to a listener that will be build into an API eventually. The issue I have is the contents that gets sent over to the listener (uses $input = @file_get_contents("php://input"); ) works with text files but cannot support binary files like a photo.
I have this for my server code:
var url = "https://proto2.sampledomain.com/uploa...";
var body = request.body();
var XHRResponse = XHR2.send("POST", url, {
"parameters": {
"userkey": "db86dfs5-4234-45f5-81ee-870e4dcffdq",
"vp": "test_data"
},
"headers": {
"X-API-KEY": "2034d2c8-7h0-449a-9944-7690e4dcffdw",
"sessionid": "kljafd23jlkjl23lkj",
"Content-type": "application/octet-stream"
},
"body": body
});
Apperyio.response.success(XHRResponse.body, "application/json");
And I have this for the service that gets invoked:
if ($scope.files.length === 0) {
alert('No file for upload');
return;
}
//insert code below....below
var requestData = {};
requestData = (function mapping7638($scope){
var requestData = {};
requestData.data = {};
var files_scope = $scope.files;
var formData = new FormData();
formData.append("file",files_scope[0].filepointer);
//requestData.data = files_scope[0].filepointer;
requestData.data = formData;
Code: Select all
return requestData;
/*CLICK TO EDIT MAPPING*/
})($scope);
// read more about using rest services: https://links.appery.io/ve-snippet-rest
Apperyio.get("upload_service")(requestData).then(
function(success){ // success callback
/CLICK TO EDIT MAPPING/
},
function(error){ // callback to handle request error
},
function(notify){ // notify callback, can fire few times
});
I followed the tutorial that was for sending files to the database and made similar mappings of data. I'm able to launch the app and select a file and upload the file. I see the file hit my listener and it looks like this:
------WebKitFormBoundary3pzFXoh0wzwGWVeA
Content-Disposition: form-data; name="file"; filename="ExamFileLog-2-9-2019-15-24-49.txt"
Content-Type: text/plain
88880418-Cons 101 RP Test -successful and is available to student
------WebKitFormBoundary3pzFXoh0wzwGWVeA--
However, when i try to write out a binary file the file is corrupted.