如何从UIImagePickerControllerReferenceURL获取UIImagePickerControllerMediaURL?

时间:2016-02-11 08:14:35

标签: ios uiimagepickercontroller

有没有办法从ReferenceURL获取MediaURL?我想将图像上传到需要filePath的S3服务器。

提前致谢。

1 个答案:

答案 0 :(得分:0)

MediaURL您可以获得ReferenceURL,您需要保存&#39; UIImage in your DocumentDirectory`然后您可以获取该路径并将其上传到S3。< / p>

let imageName = "temp.png"
let documentDirectory = try! NSFileManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
let imgPathUrl: NSURL = documentDirectory.URLByAppendingPathComponent(imageName)    
let data = UIImagePNGRepresentation(UIImagePickerControllerOriginalImage)
data!.writeToFile(imgPathUrl!.path!, atomically: true)
print("Path \(imgPathUrl!.path!)")

现在您可以从该路径上传!