Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Accessing Sandbox Directories
Started by zach78 Jul 05 2017 10:04 AM

8 replies to this topic

Best Answer Rob Miracle , 04 August 2017 - 10:50 AM

Have you tried:

 

local img = display.newImage( "../someimage.png", system.ApplicationSupportDirectory)
 

Rob

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

zach78

[GLOBAL: userInfoPane.html]
zach78
  • Observer

  • 8 posts
  • Corona SDK

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!


Edited by zach78, 23 July 2017 - 08:49 AM.


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

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



[TOPIC: post.html]
#3

zach78

[GLOBAL: userInfoPane.html]
zach78
  • Observer

  • 8 posts
  • Corona SDK

/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.



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

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

 

Rob



[TOPIC: post.html]
#5

zach78

[GLOBAL: userInfoPane.html]
zach78
  • Observer

  • 8 posts
  • Corona SDK

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...



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

  Best Answer

Have you tried:

 

local img = display.newImage( "../someimage.png", system.ApplicationSupportDirectory)
 

Rob



[TOPIC: post.html]
#7

zach78

[GLOBAL: userInfoPane.html]
zach78
  • Observer

  • 8 posts
  • Corona SDK

Tried that... doesn't seem to work, going to keep testing things...



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

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



[TOPIC: post.html]
#9

zach78

[GLOBAL: userInfoPane.html]
zach78
  • Observer

  • 8 posts
  • Corona SDK

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. 




[topic_controls]
[/topic_controls]