swift – 无法打开文件“xxx.mp4”,因为您无权查看它

swift – 无法打开文件“xxx.mp4”,因为您无权查看它,第1张

概述我使用Alamofire方法multipartFormData.append(URL,withName:“file”)将视频上传到服务器,但我收到一条错误消息: multipartEncodingFailed(Alamofire.AFError.MultipartEncodingFailureReason.bodyPartFileNotReachableWithError(file:///var/ 我使用Alamofire方法multipartFormData.append(URL,withname:“file”)将视频上传到服务器,但我收到一条错误消息:

multipartEnCodingFailed(Alamofire.AFError.MultipartEnCodingFailureReason.bodyPartfileNotReachableWithError(file:///var/mobile/Media/DCIM/100APPLE/img_0939.mp4,Error Domain=NSCocoaErrorDomain Code=257 “The file “img_0939.mp4” Couldn’t be opened because you don’t have permission to vIEw it.” UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/img_0939.mp4,NSfilePath=/var/mobile/Media/DCIM/100APPLE/img_0939.mp4,NSUnderlyingError=0x174450d10 {Error Domain=NSPOSIXErrorDomain Code=1 “Operation not permitted”}}))

我已打开隐私 – 照片库使用说明但我收到此错误,我不知道.

我的代码:

alamofireManager?.upload(    multipartFormData: { multipartFormData in        for i in 0..<vIDeoURLs.count {            multipartFormData.append(vIDeoURLs[i],withname: "file")        }    },to: url + urlString,headers: headers,enCodingCompletion: { enCodingResult in        switch enCodingResult {        case .success(let upload,_,_):            upload.uploadProgress(closure: { (progress) in                //Print progress                //print(progress)            })            upload.responseJsON { response in                if let value = response.result.value as? [String: AnyObject]{                    success(value)                }            }        case .failure(let enCodingError):            failture(enCodingError)        }    })
解决方法 你需要使用 startAccessingSecurityScopedResource

if let url = file.url,url.startAccessingSecurityScopedResource() {    multipartFormData.append(url,withname: "some-file.pdf")    // After using the resource make sure you stop the access    if url.startAccessingSecurityScopedResource() {        url.stopAccessingSecurityScopedResource()    }}
总结

以上是内存溢出为你收集整理的swift – 无法打开文件“xxx.mp4”,因为您无权查看它全部内容,希望文章能够帮你解决swift – 无法打开文件“xxx.mp4”,因为您无权查看它所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1018451.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存