Sandbox to phone

So I have a bunch of JSON files in my Documents Directory in my sandbox folder for my app. I built my app and tried to run it on my phone, but got errors because there were none of the JSON files in the phone. How can I get the Documents folder(and all my JSON files) from my computer to my phone?

This tutorial, while written for coping read only SQL files from system.ResourceDirectory to system.DocumentsDirectory will work for your JSON files as well. There is no way to automatically populate your system.DocumentsDirectory. Normally you would include them in system.ResourcesDirectory and have your app save them out. This tutorial gives you a handy function to do it for you.

https://coronalabs.com/blog/2015/05/19/tutorial-initializing-a-writable-sqlite-database-from-a-read-only-database/

Rob

Thanks so much Rob! It worked perfectly! The one problem I had is that i had to relaunch it once more after copying the files to the Documents directory. Is there a way to get around that?

Never mind, I found a workaround. Thanks so much!

I don’t know the logic of your app to be able to really answer that. If you detect a first run (i.e. a file you are trying to open doesn’t exist) and you copy things over, then once that’s done, try and re-open your files again, it should work with just the first launch.

Yeah, that’s what I did. Thanks again!

This tutorial, while written for coping read only SQL files from system.ResourceDirectory to system.DocumentsDirectory will work for your JSON files as well. There is no way to automatically populate your system.DocumentsDirectory. Normally you would include them in system.ResourcesDirectory and have your app save them out. This tutorial gives you a handy function to do it for you.

https://coronalabs.com/blog/2015/05/19/tutorial-initializing-a-writable-sqlite-database-from-a-read-only-database/

Rob

Thanks so much Rob! It worked perfectly! The one problem I had is that i had to relaunch it once more after copying the files to the Documents directory. Is there a way to get around that?

Never mind, I found a workaround. Thanks so much!

I don’t know the logic of your app to be able to really answer that. If you detect a first run (i.e. a file you are trying to open doesn’t exist) and you copy things over, then once that’s done, try and re-open your files again, it should work with just the first launch.

Yeah, that’s what I did. Thanks again!