Page 1 of 2
Loading image from database
Posted: Mon Jul 14, 2014 5:09 pm
by Erin Rasmussen
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.
Loading image from database
Posted: Mon Jul 14, 2014 5:26 pm
by Kateryna Grynko
Loading image from database
Posted: Mon Jul 14, 2014 5:39 pm
by Erin Rasmussen
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.
Loading image from database
Posted: Mon Jul 14, 2014 6:55 pm
by Kateryna Grynko
Hi Erin,
Paste a file link (http://devcenter.appery.io/documentat...) into image 'src' attribute named imageName:preApperyio("imageName").attr("src", link2file);/pre
Loading image from database
Posted: Mon Jul 14, 2014 9:05 pm
by Erin Rasmussen
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?
Loading image from database
Posted: Tue Jul 15, 2014 8:24 am
by Evgene Karachevtsev
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
Loading image from database
Posted: Tue Jul 15, 2014 1:12 pm
by Erin Rasmussen
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?
Loading image from database
Posted: Tue Jul 15, 2014 1:27 pm
by Erin Rasmussen
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.
Loading image from database
Posted: Tue Jul 15, 2014 1:38 pm
by Erin Rasmussen
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!
Loading image from database
Posted: Tue Jul 15, 2014 1:47 pm
by Evgene Karachevtsev
Erin,
Thank you for your update, glad it works!