Accessing Sandbox Directories

Is it possible to access directories other than the Corona constants (base, resource, documents, temp, and cache), within the app sandbox?

For example, the following is the Documents directory:

/var/mobile/Containers/Data/Application/<unique_id>/Documents

At the same level is the Library directory, which leads to the Caches dir:

/var/mobile/Containers/Data/Application/<unique_id>/Library/Caches/Caches

In order to use CloudKit assets I need to access this directory:

/var/mobile/Containers/Data/Application/<unique_id>/Library/Caches/CloudKit/

 

But as far as I can tell, system.pathForFile only accepts the Corona constant directory values. This would be an extremely easy fix from Corona’s end to allow access to this directory.

 

Thanks!

We support system.ApplicationSupportDirectory https://docs.coronalabs.com/api/library/system/ApplicationSupportDirectory.html This should be the /var/mobile/Containers/Data/Application/<unique_id>/Library directory. At that point you can use known paths or use LFS to look for other directories.

Rob

/var/mobile/Containers/Data/Application/<unique_id>/Library/Application Support is what I’m getting for applicationSupportDirectory, its almost there, but I can’t go “up one level” in the directory.

Have you tried using LFS and going up a directory. Do a system.pathForFile("…", system.ApplicationSupportDirectory)?

Rob

Yeah, I can use LFS to get to the directory I need, but the issue comes when I want to load the image at that location.

display.newImage() only accepts a constant as the baseDir parameter. If I were able to give it a string or the LFS working directory it would work…

Have you tried:

local img = display.newImage( “…/someimage.png”, system.ApplicationSupportDirectory)
 

Rob

Tried that… doesn’t seem to work, going to keep testing things…

In Unix based file systems / divides folders from sub folders. There are three (well four) special strings you can prefix a path with:

~/ – start at the user’s home directory

./ – start in the current directory and work down. This is pretty much the same as leading the first slash off.

…/ – move up one directory and start there

/ – start at the root directory of the device.

macOS, iOS, tvOS and Android are all based on Unix or Linux (that uses the same directory path system). Windows has a different file/directory naming scheme, but ./, …/ and / should work.  ~/ won’t work because the apps are sandboxed and you can’t get to the user’s home directory.

Rob

Got it working! Thanks! 

display.newImage( “…/someimage.png”, system.ApplicationSupportDirectory) did the trick. It didn’t work the first time because I had the wrong base in there. 

We support system.ApplicationSupportDirectory https://docs.coronalabs.com/api/library/system/ApplicationSupportDirectory.html This should be the /var/mobile/Containers/Data/Application/<unique_id>/Library directory. At that point you can use known paths or use LFS to look for other directories.

Rob

/var/mobile/Containers/Data/Application/<unique_id>/Library/Application Support is what I’m getting for applicationSupportDirectory, its almost there, but I can’t go “up one level” in the directory.

Have you tried using LFS and going up a directory. Do a system.pathForFile("…", system.ApplicationSupportDirectory)?

Rob

Yeah, I can use LFS to get to the directory I need, but the issue comes when I want to load the image at that location.

display.newImage() only accepts a constant as the baseDir parameter. If I were able to give it a string or the LFS working directory it would work…

Have you tried:

local img = display.newImage( “…/someimage.png”, system.ApplicationSupportDirectory)
 

Rob

Tried that… doesn’t seem to work, going to keep testing things…

In Unix based file systems / divides folders from sub folders. There are three (well four) special strings you can prefix a path with:

~/ – start at the user’s home directory

./ – start in the current directory and work down. This is pretty much the same as leading the first slash off.

…/ – move up one directory and start there

/ – start at the root directory of the device.

macOS, iOS, tvOS and Android are all based on Unix or Linux (that uses the same directory path system). Windows has a different file/directory naming scheme, but ./, …/ and / should work.  ~/ won’t work because the apps are sandboxed and you can’t get to the user’s home directory.

Rob

Got it working! Thanks! 

display.newImage( “…/someimage.png”, system.ApplicationSupportDirectory) did the trick. It didn’t work the first time because I had the wrong base in there.