如何捕获previewURL
数据以便将其上传到服务器?
@Published var previewURL: URL?
// file://123-123-123.mov
然后将其转换为Data
类型:
@Published var movieData = Data(count: 0)
,然后上传到我的AWS服务器
func saveVideo() async {
let uploadUrl = URL(string: postUploadData.url!)!
var requestToUpload = URLRequest(url: uploadUrl)
requestToUpload.httpMethod = "PUT"
requestToUpload.httpBody = self.movieData
do {
let (data, _) = try! await URLSession.shared.data(for: requestToUpload)
} catch {
debugPrint("Error loading (url): (String(describing: error))")
}
}
下面是我录制完视频后的回调:
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if let error = error {
print("FILE OUTPUT ERROR ----->", error.localizedDescription)
return
}
// CREATED SUCCESSFULLY
self.recordedURLs.append(outputFileURL)
self.previewURL = outputFileURL
}
在fileOutput
函数中添加以下代码:
let data = try Data(contentsOf: self.previewURL!)
print("DATA FOR MOVIE FILE ----->", data)
} catch {
print(error)
}