Need an extra pair of eyes plz
Can anyone see why this doesn't work?
Posting to http://zxing.org/w/decode
I get a Bad Image response when I submit to the form. Using the same params via the web brings back good results.
Titanium.App.addEventListener("scan_camera", function (e){
//Titanium.Media.takePicture();
var obj = new Object();
obj.imageurl = "http://www.justinhall.com/scanner/sites/default/files/scans/bw_1273007098.jpg";
Titanium.App.fireEvent("zxingit", obj);
});
Titanium.App.addEventListener("zxingit", function (e){
var xhr = Titanium.Network.createHTTPClient();
Titanium.API.info(e.imageurl);
//
xhr.onerror = function(e) {
var a = Titanium.UI.createAlertDialog({
title:'Well, this is awkward...',
message: 'We had a problem scanning your barcode - please try again'
});
a.show();
};
xhr.onload = function() {
output = 'status ' + this.status + 'n';
output += 'connected ' + this.connected + 'n';
output += 'readyState ' + this.readyState + 'n';
output += 'responseText ' + this.responseText + 'n';
output += 'responseXML ' + this.responseXML + 'n';
output += 'responseData ' + this.responseData + 'n';
output += 'connectionType ' + this.connectionType + 'n';
output += 'location ' + this.location + 'n';
var a = Titanium.UI.createAlertDialog({
title:'From ZXING',
message: output
});
a.show();
var xml = Ti.XML.parseString(this.responseText);
var table = xml.documentElement.getElementsByTagName("td");
var ean = table.item(0).firstChild.nodeValue;
actInd.hide();
if(ean.length == 13){
Titanium.App.fireEvent("findSKU", ean);
} else {
var a = Titanium.UI.createAlertDialog({
title:'Barcode Not Found',
message: "Please rescan the barcode."
});
a.show();
}
};
var img = e.imageurl;
xhr.onsendstream = function(e) {
};
//xhr.setRequestHeader('Content-Type', 'text/html;');
xhr.open('GET','http://zxing.org/w/decode');
xhr.send({
'u':img,'full':"true",'type':'Submit'
});
)};
3 Answers
-
If I'm not wrong you are trying to send an image to the server, right?
In this case you should use POST, not GETxhr.open('POST','http://zxing.org/w/decode');
-
I'm not uploading a file. The form that I'm submitting data to accepts a URL.
The image URL rests on my server.
I can submit the form with the same image URL via the browser and it works ok.
I've changed the GET to POST, but the form's type is GET.
I have done everything I can think of…
-
Fixed.
Changed the open to this:
var imgstr = Titanium.Network.encodeURIComponent(img); xhr.open('GET', 'http://zxing.org/w/decode?u=' + imgstr + '&full=true'); xhr.send();