我正在尝试上传我从iPhone录制的.mp4文件,但是它将.mov更改为API。我在调用之前检查视频URL路径,我可以确认写入文件按预期工作。我怎么能改变它?
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("didFinishPickingMediaWithInfo")
if let pickedVideo:NSURL = (info[UIImagePickerControllerMediaURL] as? NSURL) {
let videoData : Data!
do {
try videoData = Data(contentsOf: pickedVideo as URL)
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let tempPath = documentsDirectory.appendingFormat("/vid1.mp4")
let url = URL(fileURLWithPath: tempPath)
do {
try _ = videoData.write(to: url, options: [])
}
uploadVideoToAPI(tempPath)
}
}
func uploadVideoToAPI(tempPath:String) {
API.uploadVideo(URL(fileURLWithPath:tempPath)
}
class func uploadVideo(videoUrl:URL) {
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(videoUrl, withName: "profileVideo", fileName: "video.mp4", mimeType: "video/mp4")
},
to: "\(baseUrl)",method:
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
}