Ios 从iPhone设备上传视频失败,但可以在模拟器上正常工作错误:';无法读取文件';
我正在尝试从iPhone设备上传视频,如下所示:Ios 从iPhone设备上传视频失败,但可以在模拟器上正常工作错误:';无法读取文件';,ios,iphone,swift,aws-sdk-ios,Ios,Iphone,Swift,Aws Sdk Ios,我正在尝试从iPhone设备上传视频,如下所示: var uploadTask = self.session?.uploadTaskWithRequest(request, fromFile:NSURL(string: assetFilePath.path)!) 这段代码在模拟器上运行,并提供了一个会话任务对象,我可以恢复它。但它在iPhone设备上不起作用 它失败的原因是: 2015-05-19 18:36:44.718 myApp[327:24703] *** Terminating ap
var uploadTask = self.session?.uploadTaskWithRequest(request, fromFile:NSURL(string: assetFilePath.path)!)
这段代码在模拟器上运行,并提供了一个会话任务对象,我可以恢复它。但它在iPhone设备上不起作用
它失败的原因是:
2015-05-19 18:36:44.718 myApp[327:24703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot read file at file:///var/mobile/Media/DCIM/100APPLE/IMG_0144.mp4'
我试图检查视频文件是否具有读取权限,但在iPhone上返回false:
fileManager.fileExistsAtPath(asset.path) // returns false
以前有人遇到过这种情况,还是我做错了什么
我用来获取文件路径的代码是:
let options = PHFetchOptions()
options.sortDescriptors = [
NSSortDescriptor(key: "creationDate", ascending: true)
]
currentVideofetch = PHAsset.fetchAssetsWithMediaType(.Video, options: options)
let asset = self.currentVideofetch.objectAtIndex(indexPath.row) as? PHAsset
var assetLength:NSNumber!
var assetFilePath:NSString!
if let checkdAsset = asset {
PHImageManager.defaultManager().requestImageDataForAsset(checkdAsset,options: nil) {
imageData,dataUTI,orientation,info in
assetLength = imageData.length as NSNumber
let assetFilePathUrl = info["PHImageFileURLKey"] as? NSURL
assetFilePath = assetFilePathUrl!.absoluteString!
println("Assets FilePath \(assetFilePath)") // returns file:///var/mobile/Media/DCIM/100APPLE/IMG_0144.mp4
}
}
在和洛特搞砸之后。这是iOS中典型的权限问题。不幸的是,我没有得到任何直接的答案。我们必须将文件复制到我的应用程序的本地目录。从那以后,一切都变得很有魅力。
但对于大文件,我会在后台任务中发送复制文件逻辑。您是否尝试使用requestAVAssetForVideo而不是requestImageDataForAsset?