使用iOS Swift获取绝对图像文件路径 [英] Acquiring absolute image file path using iOS Swift

查看:188
本文介绍了使用iOS Swift获取绝对图像文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有没有人知道如何使用
iOS Swift从图像中获取绝对路径?我试图在HTTP post请求中发送文件路径。我
尝试了下面的代码,但处理时间太长。我正在尝试
将图像的文件路径发送到PostgreSQL数据库。任何提示
非常感谢。谢谢!

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)


推荐答案

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

这篇关于使用iOS Swift获取绝对图像文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆