如何在iOS Swift中使用Alamofire将iPhone视频上传到服务器?

时间:2016-10-05 13:08:02

标签: ios iphone swift http alamofire

当我在iPhone上录制视频时,我想按使用视频按钮上传视频并使用iOS中的 Alamofire 将其他参数发布到服务器 Swift < / strong>即可。我怎么能这样做?

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个

        Alamofire.upload(.POST, API_URL, multipartFormData: { (formData:MultipartFormData) in
        formData.appendBodyPart(fileURL: NSURL(fileURLWithPath: filePath), name: name)
        }, encodingCompletion: { encodingResult in
        switch encodingResult {
        case .Success(let upload, _, _):
            upload.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
                    print(totalBytesRead)
            }
            upload.responseJSON { response in
                    debugPrint(response)
                   //uploaded
            }
        case .Failure(let encodingError):
            //Something went wrong!
            if DEBUG_MODE {
                print(encodingError)
            }
        }
    })