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
Developer
Posts: 134
Registered: ‎04-12-2013
My Device: BB Z10
My Carrier: Telenor

show an image from the data folder

Hi,

In my app, I have few pages where I have list views. In each page, the content is got from the server as JSON.  Each list item in the listview contains an image, a title and a short description. I use a custom data model as in the quotes example. 

 

I get the JSON response from the server, parse it and save it to the database. I get the image as a URL from the JSON response. So, I download the image and save it to the data folder (data/img), and I save this path in my database for the further use. The path I use is

"/accounts/1000/appdata/com.example.test_main.testDev_ple_test_main720239b6/data/img/defaultImage.jpg"

where "test_main" is my app name. 

 

Now, when I try to retrieve this image path in the list, I get the error image not found. I am not sure if this path is not correct. Can someone suggest whats the best way to show the image from this database or data folder.

 

"

Image not found:  "/accounts/1000/appdata/com.example.test_main.testDev_ple_test_main720239b6/data/img/defaultImage.jpg" 

"Unable to get asset in (/apps/com.example.test_main.testDev_ple_test_main720239b6/native/assets/): (/accounts/1000/appdata/com.example.test_main.testDev_ple_test_main720239b6/data/img/defaultImage.jpg)." 

Please like this if you are answered.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: show an image from the data folder

Please show some code. I suspect you're using the asset: prefix but it's better if we don't have to guess.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 134
Registered: ‎04-12-2013
My Device: BB Z10
My Carrier: Telenor

Re: show an image from the data folder

bool Home::saveImage(QByteArray reply)

{

//here I have changed the code to save to different folder as I want to save all the images in the same folder

	QString filePathWithName = "data/img/";

	QString imageName;

	bool canSaveImage;

	bool canSaveInImgFolder;

	bool successfullySaved = false;

// Creating the image folder (if no created yet)

	canSaveInImgFolder = createFolder("data/img/");

	canSaveImage = canSaveInImgFolder;

	imageName = "defaultImage.jpg";

	filePathWithName += imageName;

// Saving the image on the device

	if (canSaveImage)

		successfullySaved = openAndSaveFile(filePathWithName, reply);

// If the image was succesfully saved, we pass its local address to the originating object.

	if (successfullySaved)

	{

		qDebug() << " succesfully saved image";

		QString downLoadedImagePath =
				"../../../"
						+ filePathWithName;

		qDebug() << "image path = " + downLoadedImagePath;


		QString createOrUpdateQuery =
				QString("UPDATE section SET imagePath = '%1'").arg(downLoadedImagePath);

		dbHelp.createOrUpdateRecord(createOrUpdateQuery);

		qDebug() << " succesfully displayed image";

	}

	else

	{

		fprintf(stderr, "PROBLEM Failed to save Image: %s\n", filePathWithName.toLocal8Bit().data());

	}

	return successfullySaved;
}

 Hi peter,

 

pls see the function I use to save the image and the path to the db.

 

 

Please like this if you are answered.
Developer
Posts: 134
Registered: ‎04-12-2013
My Device: BB Z10
My Carrier: Telenor

Re: show an image from the data folder

Hm.. I see that this happens only when I use a custom data source. When I use the default datasource, it works and the image gets displayed. I used the CustomSqlDataSource from the quotes example. This fetches the text and the description but not the image. 

 

Does anyone know what could be gone wrong in this?

Please like this if you are answered.