Created
March 4, 2019 13:13
-
-
Save Tayphoon/ec4554d9ce60431e49e8cb4853c75b75 to your computer and use it in GitHub Desktop.
This file contains 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
import Foundation | |
import Alamofire | |
extension MultipartFormData { | |
/// Creates a body part from the data and appends it to the multipart form data object. | |
/// | |
/// The body part data will be encoded using the following format: | |
/// | |
/// - `Content-Disposition: form-data; name=#{name}` (HTTP Header) | |
/// - `Content-Type: #{generated mimeType}` (HTTP Header) | |
/// - Encoded data | |
/// - Multipart form boundary | |
/// | |
/// - parameter object: The data to encode into the multipart form data. | |
/// - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. | |
/// - parameter decoder: The encoder to use to encode the `object` parameter. Defaults to a `JSONEncoder` | |
/// - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header. | |
public func append<T: Encodable>(_ object: T, withName name: String, encoder: JSONEncoder = JSONEncoder(), mimeType: String = "application/json") throws { | |
let data = try encoder.encode(object) | |
append(data, withName: name, mimeType: mimeType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment