Hi Illya,
I did what you described, and I can now put the photo taken by the camera in Appery.io databse with the first step.
Scondly I want to show the photo on screen, that is not done yet, no success untill now,
Third: how can I use the foto which is taken by the user for calling the OCR API?
This is also not successfull yet.
Here is my code for taking a PHOTO:
//M. Brodina (Official Rep) 1 year ago
//1) Add Camera service to project
//2) Add Camera Service on screen
//3) In Camera service settings specify destinationType = File URI
//4) Invoke service on some event
//5) On Camera service success event run the following code
function win(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
Code: Select all
var str3= r.response;
var teller=str3.indexOf('https');
alert ("teller=" +teller);
Code: Select all
ResultStr = r.response;
if (ResultStr != null) // Get the right FILE NAME out!!! thsi should be str9!!!, An easier way known ???
{
var SplitChars = 'filename":"';
if (ResultStr.indexOf(SplitChars) = 0)
{
var DtlStr = ResultStr.split(SplitChars);
var str1 = DtlStr[0];
var str2 = DtlStr[1];
var str3 ="https" + str2;
var SplitChars2 = 'fileurl":"';
var DtlStr2 = street.split(SplitChars2);
var str4 = DtlStr2[0];
var str5 = DtlStr2[1];
var str6 ="https" + str5;
var SplitChars3 = '"}';
var DtlStr3 = street2.split(SplitChars3);
var str7 ='"'+ DtlStr3[0] +'"';
var str8 = DtlStr3[1];
alert("str8 = " + str8);
var str9 ="https" + str9;
alert("str9 = " + str9);
}
}
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source);
alert("upload error target " + error.target);
}
var fileURI = data.imageURI;
var headers = {
'X-Appery-Database-Id': 'XXXXXXXXXXXXXXXX',
'X-Appery-Session-Token': localStorage.getItem("_sessiontoken")
};
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = 'image/jpeg';
options.headers = headers;
var uri = encodeURI("https://api.appery.io/rest/1/db/files/" + options.fileName);
var uri2= "https://api.appery.io/rest/1/db/files/" + options.fileName;
//alert ("uri2:", uri2);
var ft = new FileTransfer();
ft.upload(fileURI, uri, win, fail, options);
--------------------
So upload wrks, and I can get the username from the code above, I think at step 9: str9 = "THE FILE NAME I needed to dsplay on screen correct?
How can I use The filename of the photo taken by the user for OCR call which is:
function uploadFiles(url, files) {
console.log(url, files);
console.log('sending data');
var formData = new FormData();
formData.append('image', files[0]);
formData.append('language', 'fr');
formData.append('apikey', 'wXXXXX');
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
$('.translation_text').text('Translating. Please wait ... ');
xhr.onload = function(e) {
console.log(this.response);
$('.translation_text').text(this.response);
};
xhr.send(formData);
}
What should be the parameters for the function: uploadFiles(XXX,YYY) ?
what are XXX and YYYY?
Thanks
Ahmet