Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

Hi, Basically I am trying to store images in appery database as file and the image files' id's in an database table. If image had not been downloaded earlier, I want to download these images to mobile device file system. If file had already been downloaded to the phone, I want to display it in grid. Downlad part is working but I have a problem about displaying downloaded image. It's not loading anyway.

This is page setup.

Image

This is database references.

Image

And finally my code which is getting image id as a value.

precode

function fail(evt) {
alert(evt.target.error.code);
}
var fileUrl = 'https://api.appery.io/rest/1/db/files/' + deneme_settings['database_id'] +"/"+value + "?sessionToken=" + localStorage.getItem('sessionTokenId');

window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"SureTerms/"+value, {create: false, exclusive: false},
function gotFileEntry(fileEntry){
$('[dsid=pimage]', element.parent()).attr('src',fileEntry.toURL());
// Appery('pimage').attr('src', ' '+ fileEntry.fullPath+' ');
//$('img[dsid="pimage"]').attr('src',fileEntry.fullPath);
},
function fileDoesNotExist(){
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry){
var sPath = fileEntry.fullPath.replace("dummy.html","");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
fileUrl,
sPath + "SureTerms/"+value,
function(theFile) {
$('[dsid=limage]', element.parent()).attr('src',theFile.fullPath);
},
function(error) {
}
);
},
fail);
},
fail);
//fileDoesNotExist
});
},
fail);

/code/pre

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Image from file system

Hello! Are there any errors (does fail function show some alerts?)
Can you show in alert value you've set in image src? Or on service success add code which will find all images with specific name on page and show in alert src parameter for all images. Please check if src is correct and corresponding files exist on device.

Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

There isn't any error. Original code has lots of alert in fail functions(just remove them for readability) and it is creating files as expected places.

For listing image sources how can I list image sources?

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

Image from file system

Hi Mehmet,

Could you please share the app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a? We'll take a look.

Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

I shared it and "MyPackages" page has this problem. Thanks for help.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Image from file system

Hello!
1) Replace prereader.onloadend = function(evt) {
$("[dsid=pimage]").attr("src", evt.target.result);
};/pre with prereader.onloadend = function(evt) {
$("[dsid=pimage]", element.parent()).attr("src", evt.target.result);
};/pre2) Replace prefunction(theFile) {
alert("download complete: " + theFile.toURI());
alert(fileEntry.fullPath);
$('[dsid=limage]', element.parent()).attr('src',theFile.fullPath);
}/pre with prefunction(theFile) {
alert("download complete: " + theFile.toURI());
alert(fileEntry.fullPath);
$('[dsid=pimage]', element.parent()).attr('src', theFile.toURI());
}/pre

Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

Thank you for your reply but it's still not working.

Moreover I tried below ones instead of fileReader :

1) $('[dsid=pimage]', element.parent()).attr('src',fileEntry.toURL());
2) Appery('pimage').attr('src', ' '+ fileEntry.fullPath+' ');
3) $('img[dsid="pimage"]').attr('src',fileEntry.fullPath);

and these are not working too.

Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

By the way i tried alerting image path after

code$("[dsid=pimage]", element.parent()).attr("src", evt.target.result);/code

like

codealert(Appery.getImagePath('pimage'));/code

and it returns "files/views/assets/image/pimage". Maybe that can help you about problem.

If you need i can give you a username and password for application.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Image from file system

You have an error in line 28. There should be prealert(Appery.getImagePath('pimage'));/pre instead prealert(Appery.getImagePath('pimage'););/pre

Mehmet Edebali Şener
Posts: 0
Joined: Thu May 30, 2013 7:33 pm

Image from file system

I had realized that error while you were checking the code and fixed it. But my problem is still resuming. The "files/views/assets/image/pimage" path came after I fixed the line.

Return to “Issues”