Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to copy a downloaded file to our sandbox directory (iOS)
Started by support_pz Mar 24 2019 03:53 PM

- - - - -
6 replies to this topic
docpicker file ios
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

support_pz

[GLOBAL: userInfoPane.html]
support_pz
  • Observer

  • 12 posts
  • Corona SDK

Hi,

 

Firstly, I realise we don't have access to paths outside our sandbox area of our app.  However please read on.

 

We are trying to use the free DocPicker plugin (for iOS) developed by the Scott Harrison which is available here:

 

https://marketplace.coronalabs.com/corona-plugins/doc-picker

 

It's downloading the file perfectly.

 

However we are having trouble copying the downloaded file to our apps sandbox area (eg, system.DocumentsDirectory)

 

For example, the full path (which is a 'security scoped' path) of the downloaded file is:

 

file:///private/var/mobile/Containers/Data/Application/80D73BC6-DBBF-4025-A91F-97B2CFBE1F19/tmp/docpickertest/test.txt

 

The above path is OUTSIDE the sandbox area of our app.  So the document is on the device which is great but when I try to copy the file, it's not so great.

 

In order to gain access to a path outside the apps sandbox, I've come across this document from Apple of how to get access to a security scoped path.

 

https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso

 

If that is the issue, then how would I call the method outlined in the above Apple doc?  Is it possible to call a native method from lua rather than create a plugin?  Has any other Corona devs had to call this method in the past / currently?  Are you currently using the DocPicker plugin and able to copy the file to your sandbox directory even?

 

Any experience around this would be greatly appreciated.

 

Norm.

 

 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,588 posts
  • Corona SDK

Just download directly to sandbox...

 

https://docs.coronalabs.com/api/library/network/download.html

 

If that doesn't work, my copy utils might:

 

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/files/#utilities-sskfilesutil



[TOPIC: post.html]
#3

support_pz

[GLOBAL: userInfoPane.html]
support_pz
  • Observer

  • 12 posts
  • Corona SDK

Hey roaminggamer,

 

Thanks for the quick response.

 

We need to use the DocPicker plugin which gives the user the ability to choose a file (eg, from iCloud, Google Drive etc).  This plugin calls the native UIDocumentPickerViewController.  So we can't use the network api to download a file.  The plugin is working perfectly.  It's just getting access to the downloaded file outside the sandbox as mentioned above.

 

I will try to use your copy utils and report back.  Thank you for the suggestion.  I have my fingers crossed but since the file is outside the apps sandbox I'm crossing doubly hard.



[TOPIC: post.html]
#4

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,820 posts
  • Corona SDK

What happens when you try to use the built-in function within DocPicker to copy files to sandbox?



[TOPIC: post.html]
#5

support_pz

[GLOBAL: userInfoPane.html]
support_pz
  • Observer

  • 12 posts
  • Corona SDK

Hi Nick.  Are you sure there is a built-in function for the DocPicker?  I've never seen it in the Docs.  Scott (the plugin developer) hasn't mentioned it.  Are you using the DocPicker in your app?



[TOPIC: post.html]
#6

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,820 posts
  • Corona SDK

Not used it no, I just saw this in the docs:

 

docPicker.copy(fileToCopy, pathToCopy)

-- use to copy to app sandbox

 

 

fileToCopy (string) the string of url import to copy to app sand box 

 

 

pathToCopy (path) copy to url(system.pathForFile)



[TOPIC: post.html]
#7

support_pz

[GLOBAL: userInfoPane.html]
support_pz
  • Observer

  • 12 posts
  • Corona SDK

Well what do you know :-) Scott, the plugin developer just added that method today / yesterday.  I'll give it a test shortly.  If you read this Scott, thanks very much once again for looking into the problem.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: docpicker, file, ios