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

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 45
Registered: ‎04-11-2012
My Device: Z10 Limited Edition
My Carrier: 00201003883386

How to encode files to Base64 to send them to remote PC

Hello all,

               I want to send bytes (images, files, mp3,...etc) to a remote PC with meta information. I think encoding to Base64 string will be a good solution for this case.

 

But I cant find API or example for that in Cascades.  Please advise 

When you are young, work to learn. Not to earn !
Contributor
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: How to encode files to Base64 to send them to remote PC

Hi,

 

base64 encoding is available for QByteArray objects. You can load a file's content into QByteArray with QFile class. 

 

Loading is simple:

 

QFile file(QString("example.jpg"));
file.open(QIODevice::ReadOnly);

 

QByteArray loadedArray = new QByteArray(file.readAll());

 

When you have the QByteArray loaded, you can encode it to Base64 with these lines:

 

QByteArray* encodedFile = new QByteArray(loadedArray->toBase64());

 

cheers,

chriske

--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Developer
Posts: 236
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB/C, Z10
My Carrier: Sonera, Saunalahti

Re: How to encode files to Base64 to send them to remote PC

If you like to do the base64 in pure QML you can do that too, see http://qt-project.org/doc/qt-4.8/qml-qt.html#btoa-method


Kaj-Michael Lang, Home.
Author of: Onki and RetroPlayer
Contributor
Posts: 45
Registered: ‎04-11-2012
My Device: Z10 Limited Edition
My Carrier: 00201003883386

Re: How to encode files to Base64 to send them to remote PC

Thanks for reply. but I am little confused.

this method returns byte array while I need Base64 String to send it to remote PC as a JSON string . Please advise
When you are young, work to learn. Not to earn !
Contributor
Posts: 45
Registered: ‎04-11-2012
My Device: Z10 Limited Edition
My Carrier: 00201003883386

Re: How to encode files to Base64 to send them to remote PC

Thanks for reply but this sample is QML from QT website while Cascades is a modified version of QT which doesnt support all QT functionality. Are you sure is sample is working fine with Cascades?

Any way I am searching for QT/C++ code sample because I will send image as a Base64 string to wrap it in a Json String that include image and some meta information
When you are young, work to learn. Not to earn !
Contributor
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: How to encode files to Base64 to send them to remote PC

Don't worry, Cascades team just copied some parts of the Qt API reference... In Cascades documentation you can find instructions for Symbian and MeeGo too....

 

My example will work. Here is the Cascades reference:

http://developer.blackberry.com/cascades/reference/qfile.html

 

I'm sure.

--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Highlighted
Contributor
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: How to encode files to Base64 to send them to remote PC

And you can convert QByteArray to QString.

QString newString = QString(myByteArray);
--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Contributor
Posts: 45
Registered: ‎04-11-2012
My Device: Z10 Limited Edition
My Carrier: 00201003883386

Re: How to encode files to Base64 to send them to remote PC

Thank you very much. will try then mark as a solution Smiley Happy
When you are young, work to learn. Not to earn !