【问题标题】:getting error when i trying to convert AVAssetURL to Data当我尝试将 AVAssetURL 转换为 Data 时出现错误
【发布时间】:2018-05-30 19:46:29
【问题描述】:

Error Domain=NSCocoaErrorDomain Code=257 "无法打开文件“IMG_9807.MOV”,因为您没有查看权限。" UserInfo={NSFilePath=/var/mobile/Media/DCIM/109APPLE/IMG_9807.MOV, NSUnderlyingError=0x1c1e5fe00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not allowed"

我正在向其他控制器发送资产 URL 并尝试转换为数据

PHImageManager.default().requestAVAsset(forVideo: self.albumView.phAsset, options: options) { (video, audioMix, info) in
                DispatchQueue.main.async {
                     let urlAsset = video as! AVURLAsset
                    self.dismiss(animated: false, completion: {
                        self.delegate?.fusumaVideoCompleted(withFileURL: urlAsset.url)
                    })
                }
            }

下面是将 AVAssetUrl 转换为数据的方法

 do {
                let data = try Data(contentsOf: product.videoURL, options: .mappedIfSafe)
                return .upload(.multipart([MultipartFormData(provider: .data(data), name: "post[video]", fileName: "video.\(pathExtension)", mimeType: "video/\(pathExtension)")]))
            } catch {
                debugPrint(error)
            }

【问题讨论】:

标签: ios swift avasset


【解决方案1】:

正如错误告诉您的那样,您无法通过 URL 访问用户照片库中的视频文件以进行上传。您应该获取视频数据并上传。一个视频很大,不应该直接获取数据并保存在内存中;相反,将数据导出到您有权访问的位置的文件中,例如临时文件夹。

为此,您可以(例如)使用以下方法:

https://developer.apple.com/documentation/photos/phassetresourcemanager/1616280-writedata

或者这个:

https://developer.apple.com/documentation/photos/phimagemanager/1616981-requestexportsession

如果您使用“邮件”应用从自己设备的照片库中通过电子邮件发送视频,您实际上会看到这种情况发生;导出视频时,进度条会暂停,然后构建电子邮件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多