使用Alamofire上传音频二进制文件

时间:2017-12-13 09:27:23

标签: swift post alamofire multipartform-data

我正在尝试使用Alamofire以及参数和标头将音频二进制文件上传到服务器。每当我添加参数;我收到一条错误消息,指出对成员的错误参考调用错误。我已经在线检查了API,但没有找到传递参数的方法。有办法吗?

        let headersFileUpload: HTTPHeaders = ["Authorization": "JWT "+token!]
        let parametersFileUpload: Parameters = ["ctype":"yes"]

        Alamofire.upload(
            multipartFormData: { multipartFormData in
                multipartFormData.append(self.getDocumentsDirectory().appendingPathComponent("recording.m4a"), withName: "iosTest.mp3")
        },
            to: "http://localhost:8000/api/upload",
            method:.post,
            headers:headersFileUpload,
            parameters:parametersFileUpload
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        debugPrint(response)
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }
        }
        )

0 个答案:

没有答案