Loading images from tablet memory

Hello forum members,

I apologize if this has been asked before, but I did search and was unable to find my question.
I am trying to develop an app which loads images in which the file names are stored in a database. If the file exists I want to display that file, if not I wish to display a standard noimage file. I have had no problems until I try to verify if the images exist. I am using .png files, but I can switch them to .jpg. My issue is that there are several hundred of these files and I want the user to be able to add and remove files by hooking their tablet to their laptop via USB. I want to be able to place the files in the /sdcard/documents folder that lies on the tablet(not an external card, the internal memory). I am having no luck trying to “point” to that location. I can find all sort of help with the system.Documents.Directory, but that is not the correct location. Is Corona capable of opening a file stored at this location, or is this not an option?

My company wants to purchase Corona, but they want to be sure that this is possible, because this will be something we will use on many projects.

Thanks for any info you can give me.

Here is what I have been trying, but I have made many variations with no good results.

function fileExists(fileName)
local exists = false
local fileHandle = io.open( fileName,“r” )
if (fileHandle) then – nil if no file found
io.close(fileHandle)
exists = true
end
return(exists)
end

function storePic(picstring)
local strstart = string.find(picstring,“u54”)
local strend = string.find(picstring,".jpg")
local storestring2 = string.sub(picstring,strstart,strend-1)
local storeimage = “/mnt/sdcard/documents/”…storestring2…".png" --I have tried multiple variations
if fileExists(storeimage) then
return storeimage
else
return “/mnt/sdcard/documents/noimage.png”
end
end [import]uid: 181317 topic_id: 32058 reply_id: 332058[/import]

I’m not all that familiar with Android’s external storage, but in general, mobile apps live in a sandbox and do not have access to files outside of their box. That is I can’t say give me /some/path/filename.ext as that would let me access anything on the file system.

Corona SDK has four special folders that you can access for each app, which corresponds to what the OS lets you get to:

system.ResourcesDirectory – this is the App itself and how you would access files includes with the app. Android has some specialness here since the .apk is just a .zip file and the files don’t get unpacked on device. Corona extracts certain files like the images so that they can be accessed into what is seen as system.ResourcesDirectory

system.DocumentsDirectory – This is a read/write space for your app. Recently Apple has been restricting what can be put here since this folder gets backed up to iCloud. I’m unaware of Android limitations. I presume if the app is running from the SD card, then this space is on the SD card, if its running from internal storage, …

system.TemporaryDirectory – just what it sounds like… a place to write files that have no expectation of living pass your app’s run.

system.CachesDirectory – This is pretty much an iOS thing. For Compatibility, I think it maps to the TemporaryDirectory on Android. The idea here from Apple’s perspective, any file that can be downloaded from the Internet needs to go here. Facebook avatars, RSS feeds, anything that can be reproduced and redownloaded have to go here and not the the DocumentsDirectory.

Because you don’t know where your app lives, you have to make an API call to construct the path to your file.

You use system.pathForFile() to do that. See: http://docs.coronalabs.com/api/library/system/pathForFile.html This will find the appropriate system path and add your filename and any subfolders to it. So lets say want to check the caches directory and you download your pictures to a folder called “pictures” in the CachesDirectory, you would do:

local path = system.pathForFile( "pictures/mypic.jpg", system.CachesDirectory )  

Then you use that path variable as the parameter to io.open().

Corona has recently also added the Lua File System (LFS) to do advanced things like checking how old files are, getting a listing of files in a folder, etc. You can go to the Corona Blog for a discussion/tutorial on using LFS.

So the remaining issue is accessing the SD Card. Hopefully someone with more experience can chime in to see what’s available for that.
[import]uid: 19626 topic_id: 32058 reply_id: 127752[/import]

I don’t think it’s possible. Follow the link below and read Joshua’s post (#4). It was posted just back in July and I don’t think anything has changed in that regard.

http://developer.coronalabs.com/forum/2012/05/31/any-way-access-sdcard [import]uid: 56820 topic_id: 32058 reply_id: 127755[/import]

Thanks for the quick responses, but I’m not trying to access the external memory, unfortunately the file structure has sdcard in the path. I am actually trying to access a local folder on the device itself, not, removeable storage. From what I have found it seems that Corona only has access to the four folders that the app itself creates,documents,cache,temp,and resources. I am trying to access files that are already on the device, for example, if I had a picture on a sdcard and copied it to the downloads folder and then removed the sdcard, will Corona allow me to have my app use that file and display it? If so, could someone point me in the right direction.

I hope I am explaining it correctly. I’ve done things like this using Eclipse, but I really like the ease of Corona, but for some reason doing this is an issue for me. If my code is flawed then I can accept that, but if Corona isn’t capable of doing this then I need another solution.

Thank you in advance for your help. [import]uid: 181317 topic_id: 32058 reply_id: 127818[/import]

As far as I am aware you can only access those 4 folders with Corona. [import]uid: 56820 topic_id: 32058 reply_id: 127825[/import]

I’m not all that familiar with Android’s external storage, but in general, mobile apps live in a sandbox and do not have access to files outside of their box. That is I can’t say give me /some/path/filename.ext as that would let me access anything on the file system.

Corona SDK has four special folders that you can access for each app, which corresponds to what the OS lets you get to:

system.ResourcesDirectory – this is the App itself and how you would access files includes with the app. Android has some specialness here since the .apk is just a .zip file and the files don’t get unpacked on device. Corona extracts certain files like the images so that they can be accessed into what is seen as system.ResourcesDirectory

system.DocumentsDirectory – This is a read/write space for your app. Recently Apple has been restricting what can be put here since this folder gets backed up to iCloud. I’m unaware of Android limitations. I presume if the app is running from the SD card, then this space is on the SD card, if its running from internal storage, …

system.TemporaryDirectory – just what it sounds like… a place to write files that have no expectation of living pass your app’s run.

system.CachesDirectory – This is pretty much an iOS thing. For Compatibility, I think it maps to the TemporaryDirectory on Android. The idea here from Apple’s perspective, any file that can be downloaded from the Internet needs to go here. Facebook avatars, RSS feeds, anything that can be reproduced and redownloaded have to go here and not the the DocumentsDirectory.

Because you don’t know where your app lives, you have to make an API call to construct the path to your file.

You use system.pathForFile() to do that. See: http://docs.coronalabs.com/api/library/system/pathForFile.html This will find the appropriate system path and add your filename and any subfolders to it. So lets say want to check the caches directory and you download your pictures to a folder called “pictures” in the CachesDirectory, you would do:

local path = system.pathForFile( "pictures/mypic.jpg", system.CachesDirectory )  

Then you use that path variable as the parameter to io.open().

Corona has recently also added the Lua File System (LFS) to do advanced things like checking how old files are, getting a listing of files in a folder, etc. You can go to the Corona Blog for a discussion/tutorial on using LFS.

So the remaining issue is accessing the SD Card. Hopefully someone with more experience can chime in to see what’s available for that.
[import]uid: 19626 topic_id: 32058 reply_id: 127752[/import]

I don’t think it’s possible. Follow the link below and read Joshua’s post (#4). It was posted just back in July and I don’t think anything has changed in that regard.

http://developer.coronalabs.com/forum/2012/05/31/any-way-access-sdcard [import]uid: 56820 topic_id: 32058 reply_id: 127755[/import]

Thanks for the quick responses, but I’m not trying to access the external memory, unfortunately the file structure has sdcard in the path. I am actually trying to access a local folder on the device itself, not, removeable storage. From what I have found it seems that Corona only has access to the four folders that the app itself creates,documents,cache,temp,and resources. I am trying to access files that are already on the device, for example, if I had a picture on a sdcard and copied it to the downloads folder and then removed the sdcard, will Corona allow me to have my app use that file and display it? If so, could someone point me in the right direction.

I hope I am explaining it correctly. I’ve done things like this using Eclipse, but I really like the ease of Corona, but for some reason doing this is an issue for me. If my code is flawed then I can accept that, but if Corona isn’t capable of doing this then I need another solution.

Thank you in advance for your help. [import]uid: 181317 topic_id: 32058 reply_id: 127818[/import]

As far as I am aware you can only access those 4 folders with Corona. [import]uid: 56820 topic_id: 32058 reply_id: 127825[/import]

mike.sherman any luck yet?

mike.sherman any luck yet?