text 来自https://stackoverflow.com/questions/35645839/swift-upload-video-to-http-server
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 来自https://stackoverflow.com/questions/35645839/swift-upload-video-to-http-server相关的知识,希望对你有一定的参考价值。
// upload event
func uploadMedia(){
if videoPath == nil {
return
}
guard let url = URL(string: "server_path") else {
return
}
var request = URLRequest(url: url)
let boundary = "------------------------your_boundary"
request.httpMethod = "POST"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
var movieData: Data?
do {
movieData = try Data(contentsOf: url, options: Data.ReadingOptions.alwaysMapped)
} catch _ {
movieData = nil
return
}
var body = Data()
// change file name whatever you want
let filename = "upload.mov"
let mimetype = "video/mov"
body.append("--\(boundary)\r\n".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name=\"file\"; filename=\"\(filename)\"\r\n".data(using: String.Encoding.utf8)!)
body.append("Content-Type: \(mimetype)\r\n\r\n".data(using: String.Encoding.utf8)!)
body.append(movieData!)
request.httpBody = body
let task = URLSession.shared.dataTask(with: request) { (data: Data?, reponse: URLResponse?, error: Error?) in
if let `error` = error {
print(error)
return
}
if let `data` = data {
print(String(data: data, encoding: String.Encoding.utf8))
}
}
task.resume()
}
以上是关于text 来自https://stackoverflow.com/questions/35645839/swift-upload-video-to-http-server的主要内容,如果未能解决你的问题,请参考以下文章
来自 watchOS 中 if 条件 Text() 的 SwiftUI 运行时错误
text 来自ip的Wget
text 来自apto列表的回复
text 来自Adam的测试片段
text BM1682支持来自Caffe算子
text 来自cli的mysql查询