Проблема с загрузкой видео в Alamofire

Я получаю сообщение об ошибке при загрузке видео на сервер.

Ошибка -> Error Domain=NSCocoaErrorDomain Code=257 "Файл â € œtrim.18B96B49-EDDB-4A79-9494-E67C9DD50CF5.MOV не может быть открыт, потому что у вас нет разрешения на его просмотр.

Пример кода ->

Alamofire.upload(multipartFormData: { (multipartFormData) in


            if(imageDataArr.count > 0)
            {
                for obj in imageDataArr
                {
                    let imageFile = obj

                    if let imageData =  imageFile.jpegData(compressionQuality: 0.5)
                    {
                        multipartFormData.append(imageData, withName: "post_upload_file", fileName:randomFileName, mimeType: mimType)
                    }
                }

            }
            if(!fileData.isEmpty)
            {

                for i in 0...fileData.count-1
                {

                    let mediaFile =  fileData[i]
                    let fileURL = URL(string: mediaFile)
                    let result = fileURL!.startAccessingSecurityScopedResource()
                    print(result)
                    multipartFormData.append(URL.init(string: mediaFile)!, withName: "post_upload_file", fileName:randomFileName, mimeType: mimType)

                }
            }

            for (key, value) in requestDict ?? [:]
            {
                print(key)
                print(value)
                multipartFormData.append("\(value)".data(using: String.Encoding.utf8)!, withName: key as String)
            }

            //                                for (key, value) in requestDict ?? [:] {
            //                                    multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
            //                                }
        }, to: urlComplete, method: method, headers: headers, encodingCompletion: { (Result) in
            switch Result {
            case .success(let upload, _, _):
                upload.responseJSON(queue: DispatchQueue.main, options: JSONSerialization.ReadingOptions.allowFragments, completionHandler: { (response) in
                    //print(response.re)
                })
                upload.responseJSON(completionHandler: { response in
                    switch(response.result) {

                    case .success(_):

                        if response.result.value != nil
                        {
                            let statusCode = (response.response?.statusCode)!
                            print("...HTTP code: \(statusCode)")
                            var responseDict = [String: Any]()

                            if let jsonDict = response.result.value as? [String: Any]
                            {
                                responseDict = jsonDict
                            }
                            //let message = responseDict["message"] as! String
                            print(responseDict)
                            compBlock(responseDict, response)
                        }
                        break
                    case .failure(_):
                        failure(response.result.error!)
                        break
                    }
                })
                break
            case .failure(let Result):
                print(Result.localizedDescription)
                failure(Result)
                break
            }
        })

0 ответов

Другие вопросы по тегам