Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: POST/READ data to PHP/MYSQL on webserver

Hi Justam,

 

Regex isn't my expertise, but I'll look into this. Shot in the dark, could you try the following? I think we may have to escape the characters in the regex as well. The bold part represent \/.

 

var string=obj.base64.replace(/\\\//g,"/");

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

The regex I was using works fine, fixes all the \/. I checked by printing the results on screen. Seems to stop @ stringToBlob....which is the next line. Is the call blackberry.utils.stringToBlob or just stringToBlob?
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: POST/READ data to PHP/MYSQL on webserver

The call should be:
blackberry.utils.stringToBlob

 

Is your code wrapped in a try/catch block? If not, I would recommend something along the lines of:

 

try {
    var string=obj.base64.replace(/\//g,"/");
    var pic =  blackberry.utils.stringToBlob(string, 'binary');
    contact.setPicture = pic;
    alert("Done.");
} catch (err) {
    alert("Error: " + err);
}

This way, we should either see "Done." or "Error: " with some sort of explanation.

 

If we see nothing, then the line would be hanging, meaning some deeper problem with stringToBlob.

 


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

[ Edited ]

Hello Erik, 

 

Yes, good idea. Testing now...I have the database initalisation wrapped around a try/catch aswell. But when testing on a 9800 OS6.0.0.668 the app hangs right after executing the function call...it doesn't proceed through the commands in the function and no errors are thrown...

 

function openUDB() {
alert("Function executed...");
	"use strict";
	try {
		if (window.openDatabase) {
			alert("Opening DB.");
			mynamespace.db = window.openDatabase('proqaccount' + blackberry.identity.PIN, 'ver' + blackberry.identity.PIN, 'data' + blackberry.identity.PIN, 5 * 1024 * 1024, onDBCreate);
			if (mynamespace.db) {
					document.querySelector("#init").style.display = 'block'; 
					document.querySelector("#initstatus").innerHTML = "<br/><br/><br/><br/><center>Initialising...</center>";
					alert("DB successfully opened.");
					selectDB();			
			} else {
			
				throw "window.openDatabase returned null.";
			}
		} else {
			throw "window.openDatabase does not exist.";
		}
	} catch (err) {
		
		alert(err);
	}
}

 

function onDBCreate(database) {
	"use strict";
	alert("db create function");
	try {
		if (database) {
			//Not required, but setting mynamespace.db in case we want to add additional setup code here later on.
			mynamespace.db = database;
		} else {
			throw "New DB could not be created.";
		}
	} catch (err) {
	
		alert(err);
	}
}

 

Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

Hello Erik, 

 

The result of the try catch for the stringToBlob is; Error: null.

 

Here is my block:

 

try {
	var string=obj.base64.replace(/\//g,"/");
	alert(string);
	var pic =  blackberry.utils.stringToBlob(string, 'binary');
	contact.setPicture = pic;
	alert("Done.");
} catch (err) {
	alert("Error: " + err);
}

 The alert(string); is showing the proper base64 after the regex so there is data being passed to stringToBlob...

Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

Hello Erik, 

 

 

I'm wondering if its even possible passing the base64 or binary data to setPicture to assign a picture. I may be understanding this incorrectly but it seems in the example in the api docs that it is reading the blobdata from the file in the filesystem and then passing this blob data to .setPicture.

 

What I don't see in the example is the encoding/decoding...

 

I have a feeling I'm way off on this one.....the reason I'm thinking passing the base64 right to .setPicture should work is in the api docs it states contact.picture is readonly in a base64 format so based on that if I call var data = contact.picture; it should read out the base64 data of the contact image which I have selected. Secondly vcard images are stored using base64 data...so if contact.firstname=Frank can be accepted as an ascii entry for the vcard as the name field in a vcard is ascii then logically I would assume it would be the same for .setPicture but with base64 ofcourse.

 

Just my rambling thoughts and it doesn't seem to operate that way, I'd really like to figure this out...so it makes sense to me haha....

 

 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: POST/READ data to PHP/MYSQL on webserver

[ Edited ]

Hello Justam,

I missed this when scanning the code earlier. contact.setPicture is a function, not a property. Therefore the current call:
contact.setPicture = pic;

Should actually be:
contact.setPicture(pic);

I agree with your reasoning that passing the base64 data should work. In either case, we have the blob representation of a base64 string that holds image data. Whether that data was originally inserted by a read file, or by our own method should not make a difference.

One alternative approach to this would be to read the blob data from a known picture file (that works), then verify that data and use the exact same string in your database. From there, attempt to read the database string with your method (verify that it is the same as the read file approach), and attempt to set the picture.

I haven't had the opportunity to test this myself unfortunately, I've been travelling since Sunday and am not back in the office until June 11. I will try to find the opportunity to test this before then, but if you can verify the same contents of a known working file, I think that would be the best approach here.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

[ Edited ]

Hello Erik, 

 

aha! I missed that too, alright will test as suggested. 

 

Unfortunately I was a couple hours late for registration for Blackberry Jam Toronto. I had some unforseen events very early in the morning and wasn't around my cpu/berry to be notified that registration was open. By the time I got to my cpu @ lunch the registration was full...Smiley SadSmiley Sad Figures too because I was checking the website every morning for registration information and they day I couldn't was registration ....which was a really big dissapointment  for me, I was looking forward to the event and connecting with RIM, not to mention, I have a large corporate project coming up and could have really used the 1 on 1 with a dev like yourself to discuss possible methods of execution. Although I am pretty sure I  will be using TCP and possibly PUSH aswell. Anyways...

 

I will test and report back. Also I am going to find a 9800 somewhere and load up .668 to confirm if that hanging is OS and not simulator specific. 

 

 

 

 

Contributor
Posts: 13
Registered: ‎05-31-2012
My Device: 9360
My Carrier: Vip

Re: POST/READ data to PHP/MYSQL on webserver

Hi,

 

I have another problem related to this, maybe you can help me.

 

Software that I use:

Ripple emulator 0.9.4.1

Blackberry 9930 Simulator

 

I have no real device.

 

Problem:

In Ripple emulator post to local php script (and reply) works just fine (using XMLHttpRequest() object), but in Blackberry simulator nothing happens. Is this normal in simulator, and works in real device, or I have to change something in code/settings?

 

Thanks.

Developer
Posts: 58
Registered: ‎02-14-2011
My Device: Bold 9700
My Carrier: Rogers

Re: POST/READ data to PHP/MYSQL on webserver

[ Edited ]

I always use the MDS which comes with the JDK/JDE, it allows me to verify the request/responses and I have found these things dont work without the MDS running. Are you running MDS?