Save image from URL and make it accessible only for current app

Hello, I am working on a puzzle game and I need to load some images from URLs and save it on the phone. I do not want the images to be available for other apps (like galleries). The images should be accessible locally only from the app that I am working on. How can I save images such accessibility settings and also, how do I get and display such images in code?

I need some clarification regarding the ‘accessibility’ requirements.

Which do you mean (choose one only):

#1 - You want to be able to download the images and view them in your app, but not allow any other apps on same device to see the images.

#2 - You want to restrict downloads of the images to your app only.  i.e. even if someone had the URL to the image, only your app could download them.

#3 - Same as #2 plus a URL would be specific to a single app and user.  i.e. Two users of your app could not both see the image at a URL.

I will respond with thoughts on a solution once you select between these options for further clarify.

Hi roaminggamer and thank you for you quick reply.

I mean #1

I see that my explanation of the problem was unclear. So here are more details:

  1. Images are hosted publicly

  2. I need my app to download AND store them on the device

  3. I do not want other apps to “see” that images, this images must be stored in a kind of memory that is “dedicated” to my app like project images that we use in Corona projects.

If you have more questions feel free to ask :slight_smile:

You’re in luck.  This is easily achieved and I have examples.

  1. You can save the files to the system.documents or system.temporary folders and no other apps* will be able to see them.

* caveat - A rooted device may be able to run apps that can see these folders.  However for normal users, these images are in the app’s sandbox and thus only visible to your app.

  1. I updated my old examples here showing how: 

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2016/09 (remoteFiles and remoteFiles2)

Direct download links (includes SSK2):

As you will have noticed, these are part of my rather extensive AskEd collection ( > 250 answers from 2014 … 2017) in the RG_FreeStuff repository.  Remember this exists for future questions.

While both examples use SSK2 for my convenience ( string.split and other functions) it is not required for the core of the solution.

WOW! Your repository is awesome :slight_smile:

This is exactly what I needed. I want to restrict access to images from other apps just not to spam users’ galleries so rooted devices will not be a problem. Just quick question: in  networkListener function (in main.lua) does event.phase == “ended” mean that the image was successfully downloaded?

Thank you very much!

Yes.  

Everything you need to know about the function network.download() (including info about the listener) is here: https://docs.coronalabs.com/api/library/network/download.html

I need some clarification regarding the ‘accessibility’ requirements.

Which do you mean (choose one only):

#1 - You want to be able to download the images and view them in your app, but not allow any other apps on same device to see the images.

#2 - You want to restrict downloads of the images to your app only.  i.e. even if someone had the URL to the image, only your app could download them.

#3 - Same as #2 plus a URL would be specific to a single app and user.  i.e. Two users of your app could not both see the image at a URL.

I will respond with thoughts on a solution once you select between these options for further clarify.

Hi roaminggamer and thank you for you quick reply.

I mean #1

I see that my explanation of the problem was unclear. So here are more details:

  1. Images are hosted publicly

  2. I need my app to download AND store them on the device

  3. I do not want other apps to “see” that images, this images must be stored in a kind of memory that is “dedicated” to my app like project images that we use in Corona projects.

If you have more questions feel free to ask :slight_smile:

You’re in luck.  This is easily achieved and I have examples.

  1. You can save the files to the system.documents or system.temporary folders and no other apps* will be able to see them.

* caveat - A rooted device may be able to run apps that can see these folders.  However for normal users, these images are in the app’s sandbox and thus only visible to your app.

  1. I updated my old examples here showing how: 

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2016/09 (remoteFiles and remoteFiles2)

Direct download links (includes SSK2):

As you will have noticed, these are part of my rather extensive AskEd collection ( > 250 answers from 2014 … 2017) in the RG_FreeStuff repository.  Remember this exists for future questions.

While both examples use SSK2 for my convenience ( string.split and other functions) it is not required for the core of the solution.

WOW! Your repository is awesome :slight_smile:

This is exactly what I needed. I want to restrict access to images from other apps just not to spam users’ galleries so rooted devices will not be a problem. Just quick question: in  networkListener function (in main.lua) does event.phase == “ended” mean that the image was successfully downloaded?

Thank you very much!

Yes.  

Everything you need to know about the function network.download() (including info about the listener) is here: https://docs.coronalabs.com/api/library/network/download.html