Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

Hi, I'm trying to run an app that searches for a specific entry in a database and displays the image associated with the entry. The file name is saved in one of the columns and I was able to correctly query the database and get the file name saved to a local variable but I'm not sure how to display the image in my app.

I'm new to java and to Appery so any help would be greatly appreciated.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Loading image from database

Hi Erin,

Please take a look here: http://devcenter.appery.io/documentat...

Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

I've read through the page but what I can't figure out is how to set the image to an "image" component. Also, under the 'Retrieving files' heading, it says to add the file name to the end of the URL, but I don't know how to set it so that it changes for different files.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Loading image from database

Hi Erin,

Paste a file link (http://devcenter.appery.io/documentat...) into image 'src' attribute named imageName:preApperyio("imageName").attr("src", link2file);/pre

Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

This is the code I'm using. I decided to try uploading using a static file name and getting that to work before I use a variable for the file name. When I test the app, the image doesn't load. Is there something I'm doing wrong? Image Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Loading image from database

Hello Erin,

Could you please detail, you make the mapping of file name to asset of component Image? Or do you on the success of the service launch js which changes src pictures?
By the way in the code on the first screenshot you do not have databaseID. URL should look like this

prehttps://api.appery.io/rest/1/db/files/[databaseID]/[fileName]/pre

Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

After the success of a service, I am launching a java script to change the picture.
And thank you, the databaseID was what I was missing. It's loading the file now.

If I were to use a variable for the file name, how could I add that to the end of the rest of the path string?

Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

I should be more specific, I'm using concat() to append my path string, but I can't figure out how to call the local variable that I have the file name stored in.

Erin Rasmussen
Posts: 0
Joined: Mon Jul 14, 2014 5:09 pm

Loading image from database

I figured it out. I used localStorage.getItem() and saved it to var2 and saved the first half of the path to var1. Then I used var1.concat(var2). Thank you for all the help!

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Loading image from database

Erin,

Thank you for your update, glad it works!

Return to “Issues”