Acquiring absolute image file path using iOS Swift

余生长醉 提交于 2019-12-13 00:35:05

问题


Does anyone know how to acquire the absolute path from an image using iOS Swift? I am trying to send the file path in a HTTP post request. I have tried the code below but it takes too long to process. I am trying to send the file path of an image to a PostgreSQL database. Any tips are greatly appreciated. Thank you!

var paths: NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
   var documentDirectory: NSString = paths.objectAtIndex(0) as NSString
   var localFilePath: NSString = documentDirectory.stringByAppendingPathComponent("image.png")
   var data: NSData = UIImagePNGRepresentation(image)
   data.writeToFile(localFilePath, atomically: true)

回答1:


let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first as NSURL
if let fileAbsoluteUrl = documentsUrl.URLByAppendingPathComponent( "image.png").absoluteURL {
    println(fileAbsoluteUrl)
}


来源:https://stackoverflow.com/questions/27774401/acquiring-absolute-image-file-path-using-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!