Created
August 15, 2019 10:45
-
-
Save InukVT/cfa8bbaaa2b5c4cad14a0da809cda3c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public func upload(parts: [Content], url: uploadUrl) throws -> Future<Response> { | |
| var b2Headers: [String: String] = ["Content-Type": "multipart/form-data; boundary=-123-"] | |
| b2Headers["Content-Length"] = // Err... We'll figure this out later | |
| let headers = HTTPHeaders(b2Headers.map { $0 }) | |
| let request = Request(using: self.client.container) | |
| request.http.method = .POST | |
| request.http.headers = headers | |
| request.http.body = "" | |
| for part in parts { | |
| var appendPart = "" | |
| if let file = part as File { | |
| appendPart.append("Content-Disposition: form-data; name=\(file.filename); filename=\(file.filename)\n") | |
| appendPart.append("Content-Type: \(file.contentType)\n\n") | |
| appendPart.append(data) | |
| } | |
| //also append to appendPart if it's not a File, idk it's pseudo code | |
| request.http.body.append(appendPart) | |
| } | |
| request.http.url = uploadURL! | |
| return self.client.send(request) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment