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

Reply
Trusted Contributor
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Hi,

I want to download some files(e.g. Image files or Mp3 files or video files) from a URL Link and store those files to SD Cards.

But I didn't find any codes related to solve my problem.
Please Help me if any one done such work or having any solution regarding to this Problem. 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Developer
Posts: 49
Registered: ‎08-21-2012
My Device: Blackberry z10 LE
My Carrier: Vodafone

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Using QNetworkAccessManager you can download what you want...

 

Nokia Qt Ambassador
http://www.softairrealfight.net
Trusted Contributor
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Hi AlterX,
Is there any possible way for Cascades code not for QT.
I want the code for Cascades.

Please help me... 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Retired
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Retired
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

BTW, there are some new samples published.

Download all samples: git clone https://github.com/blackberry/Cascades-Samples.git

 

Import into momentics:
File/Import, git/projects from git (next), double-click local and add a local directory (next), select local directory and select all projects (default is select ones that aren't in your workspace)

 

Check out HttpTestSample and MultithreadingCallbacks102

 

The latter sample demonstrates how a call is made to perform a network operation to download an image and display it in the UI.

The image download uses QNetworkAccessManager and QNetworkReply with slots and signals to handle the download callback. See method "void LoadImage::load(QString imageUrl)"

After downloading "void LoadImage::smileysurprised:nReplyFinished()" has the code to extract the bytes downloaded and stores it in a byte array.

QImage::loadFromData() loads the bytes downloaded into a QImage object.

To show it in the UI see the following method "void App::smileysurprised:nImageLoaded(QString url, bool success, QString response)"

QImage is loaded into a bb::cascades::smileytongue:ixelBufferData, and bb::cascades::Image() is used to load the PixelBufferData.

Finally ImageView::setImage() is called with the updated bb::cascades::Image object to display it in the UI.

 

Stuart

Retired
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

See also: https://developer.blackberry.com/cascades/documentation/device_platform/networking/index.html

 

You can navigate to this page right off the main documentation page https://developer.blackberry.com/cascades/!

Press Documentation, scroll down, and press Networking.

 

Stuart

Developer
Posts: 22
Registered: ‎03-05-2011
My Device: Not Specified

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Hi, i browsered the code on the site and there is not such one anymore, do you happen to have it? or any other site where i can download it¿

 

Thank you!

Contributor
Posts: 28
Registered: ‎07-04-2013
My Device: BB, 86ABC
My Carrier: IDEA

Re: Download Files From URL Link And Store The Files In Local Folder or SD Card In BB10 Cascades

Use the following code. Its working for me.

 

 

QImage image;

        image.loadFromData(buffer);

        image = image.scaled(768, 500, Qt::KeepAspectRatioByExpanding);

        const QImage swappedImage = image.rgbSwapped();
        const bb::ImageData imageData = bb::ImageData::fromPixels(swappedImage.bits(), bb::smileytongue:ixelFormat::RGBX, swappedImage.width(), swappedImage.height(), swappedImage.bytesPerLine());
        bb::utility::ImageConverter::encode(QUrl(QDir::currentPath() + "/shared/camera/img.png"), imageData, 75);

 

 

in the above code "buffer"is instance of QByteArray. Convert inputstream to QByteArray and use above code.