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
Regular Contributor
Posts: 68
Registered: ‎06-12-2012
My Device: Blackberry Bold 9780
My Carrier: Vodafone

Re: Save form to server

Found this: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Overwriting-a-file-using-HTML5-o...

Hopefuly that will help you, if you loading it works but you just cant convert it give me a shout Smiley Happy
Developer
Posts: 30
Registered: ‎06-14-2012
My Device: 9810
My Carrier: Telkomsel

Re: Save form to server


liammccann wrote:
Found this: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Overwriting-a-file-using-HTML5-o...

Hopefuly that will help you, if you loading it works but you just cant convert it give me a shout Smiley Happy

This is my code, from link that you gived :

var fullPath = document.getElementById('uploadImage').value;

if (fullPath) 

           {

var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
var filename = fullPath.substring(startIndex);
if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0)
{
filename = filename.substring(1);

}

 

}

 

var fileData = "file:///SDCard/BlackBerry/pictures/"+filename;

var myData = blackberry.utils.blobToString(fileData,"BASE64");

alert(myData); 

}

 

and myData is still empty

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Save form to server

Hi there,

 

Although I've never used this functions I think you are doing it wrong. blobToString takes blob data, not a filename. You are just passing the filename in the argument.

Check the example in the API docs: https://developer.blackberry.com/html5/apis/blackberry.utils.html#.blobToString

 

Hope it helps

 

Nuno
Highlighted
Developer
Posts: 30
Registered: ‎06-14-2012
My Device: 9810
My Carrier: Telkomsel

Re: Save form to server


nunodonato wrote:

Hi there,

 

Although I've never used this functions I think you are doing it wrong. blobToString takes blob data, not a filename. You are just passing the filename in the argument.

Check the example in the API docs: https://developer.blackberry.com/html5/apis/blackberry.utils.html#.blobToString

 

Hope it helps

 


If you mean  :

var file= document.getElementById('uploadImage').files[0];

var myData = blackberry.utils.blobToString(fileData,"BASE64");

alert(myData); 

 

same to me


Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Save form to server

you are still passing a string with the filename.
Nuno
Developer
Posts: 30
Registered: ‎06-14-2012
My Device: 9810
My Carrier: Telkomsel

Re: Save form to server


nunodonato wrote:
you are still passing a string with the filename.

Can you help me with the right code Nuno ?

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Save form to server

did you read the link I sent you? The example is quite simple.
First, you need to open the file (using the filename), the callback function will give you the blobData, Then you can use it with blobToString.
There's a full example in the API docs.
Nuno
Developer
Posts: 30
Registered: ‎06-14-2012
My Device: 9810
My Carrier: Telkomsel

Re: Save form to server

This is my code :

 

var fullPath = document.getElementById('uploadImage').value;
if (fullPath)
{
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
var filename = fullPath.substring(startIndex);
if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0)
{
filename = filename.substring(1);
}
try{
var fileData = "file:///store/home/user/pictures"+filename;
if (blackberry.io.file.exists(fileData))
{
blackberry.io.file.readFile(fileData, handleOpenedFile);
}
}
catch (ex)
{
alert("exist: " + ex.toString(0));
}
}
}

 

function handleOpenedFile(fullPath, blobData)
{
xmlString = blackberry.utils.blobToString(blobData);
alert(xmlString);
}

 

xmlString seems empty 

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Save form to server

do you get an empty alert box?

have you tried some debugging using the inspector?

Nuno
Developer
Posts: 30
Registered: ‎06-14-2012
My Device: 9810
My Carrier: Telkomsel

Re: Save form to server


nunodonato wrote:

do you get an empty alert box?

have you tried some debugging using the inspector?


There is no alert at all

I'm using device to test it.

Or maybe my device is the problem it self ? I'm using torch 9810