Page 1 of 4

Image from file system

Posted: Tue Nov 26, 2013 7:29 pm
by Mehmet Edebali Şener

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


Image from file system

Posted: Tue Nov 26, 2013 8:30 pm
by Maryna Brodina

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.


Image from file system

Posted: Tue Nov 26, 2013 9:36 pm
by Mehmet Edebali Şener

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?


Image from file system

Posted: Wed Nov 27, 2013 4:18 pm
by Kateryna Grynko

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.


Image from file system

Posted: Thu Nov 28, 2013 8:04 am
by Mehmet Edebali Şener

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


Image from file system

Posted: Thu Nov 28, 2013 6:46 pm
by Maryna Brodina

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


Image from file system

Posted: Thu Nov 28, 2013 8:12 pm
by Mehmet Edebali Şener

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.


Image from file system

Posted: Thu Nov 28, 2013 8:26 pm
by Mehmet Edebali Şener

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.


Image from file system

Posted: Thu Nov 28, 2013 8:49 pm
by Maryna Brodina

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


Image from file system

Posted: Thu Nov 28, 2013 9:28 pm
by Mehmet Edebali Şener

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.