Page 1 of 1

Getting list of images from database

Posted: Tue Sep 03, 2013 6:53 pm
by Mehmet Edebali Şener

Hi,
While fetching a list of informations which includes pictures from a database table, I fetch the list of the names of that pictures and trying to show each of the pictures that I got its names with the code below :

var data2;
var serverUrl = 'https://api.appery.io/rest/1/db/files/' + value;
$.ajax({
type: "GET",
headers: {'X-Appery-Database-ID':deneme_settings['database_id'],'X-Appery-Session-Token':localStorage.getItem('sessionTokenId')},
url: serverUrl,
processData: false,
success: function(data) {
console.log("Successfully loaded");
data2= "data:image/png;base64," + data;
flag = false;
},
error: function(xhr) {
console.log("Load error: " + xhr.status + " " + xhr.responseText);
}
});
return data2;

The code returns before the picture is uploaded, so the place that the picture should be there stays blank. How can I make wait the code to provide it is uploaded before returning?

Best regards,
Edebali


Getting list of images from database

Posted: Tue Sep 03, 2013 7:53 pm
by Maryna Brodina

Hello! If we understand correctly you have this code in response Mapping? $.ajax function work is not sync. So you need to change your code https://gist.github.com/anonymous/29a...


Getting list of images from database

Posted: Tue Sep 03, 2013 8:51 pm
by Mehmet Edebali Şener

Thank you for quick reply. Yes i using this code in response mapping. it is getting image name as value. My mapping looks like below:
Image

when i used the code that you suggested i get the "Failed to load resource " error at
"$(element).attr('src', data2);"
line.

What do you think about the reason of the error?


Getting list of images from database

Posted: Wed Sep 04, 2013 6:49 am
by Mehmet Edebali Şener

by the way i am loading files directly via appery database interface. They are not base64 images.


Getting list of images from database

Posted: Wed Sep 04, 2013 7:11 am
by Mehmet Edebali Şener

I made it with "Direct link to a file".

http://docs.appery.io/documentation/b...

Thanks for advice again.


Getting list of images from database

Posted: Wed Sep 04, 2013 9:01 am
by Anton Artyukh5836028

Glad to hear that. Thanks for a notice.