I have a NSURL
object which gives me the path of a local file (in documents folder). I want to populate an NSData
object with the contents of this file. Tried using dataWithContentsOfURL:
but this fails. I know the file exists because the iPhone SDK
returns the path.
Can someone please tell me how I can get an NSData
object from the URL
of a local file?
Thanks.
For swift3 I found answer from following URL helpful
( I was getting following path , after capturing image using phonegap plugin
file:///var/mobile/Containers/Data/Application/B64B06DE-7976-45CF-9BE2-661F0F309A06/tmp/abcded.jpg )
https://stackoverflow.com/a/41043447/6383908
if let videoURL = URL(string: urlString), let videodata = try? Data(contentsOf: videoURL) { //Add code of Alamofire here }
To get this work you just need to do:
Make sure your local URL starts with "file://" then you would just have to do this: