0
votes

I have a permission issue while going to fetch video from following url :

"file:///var/mobile/Media/DCIM/101APPLE/IMG_1111.mp4"

I am getting the following error , while going to get data from above url :

Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_1111.mp4” couldn\342\200’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/101APPLE/IMG_1111.mp4, NSUnderlyingError=0x1c0440f30 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

My code to get data is :

do {
     let fileData = try Data.init(contentsOf:urlCheck)
     print(fileData)
   } catch { 
     print(error)
   }

Any help will be appreciated. Thanks

1
are you sure your urlCheck is made using let urlCheck = NSURL(fileURLWithPath: filePath) ???Ankit Kushwah
Are you in Playground by any chance?regina_fallangi
@AnkitKushwah i have changed that with let fileData = try Data.init(contentsOf:NSURL(fileURLWithPath: urlCheck.absoluteString) as URL) --- but still its samepuja
@puja can you first try on simulator ??Ankit Kushwah
do { let Data = try Data(contentsOf: urlCheck l as URL) } catch { print("Unable to load data: (error)") }Ankit Kushwah

1 Answers

0
votes

I don't think you can access files from any folders or paths that are not part of your application. The file must be placed inside the application folder only. Either Document, Temp, or other folders.

This is because all applications are SANDBOXED and thus, can't access data from other applications directly.

If you are trying to access data from Photos, or any other app, you will need to save it to your application's sandboxed directory before reading it.

Reference: iOS Application Sandboxing