2 // OAuthSwiftMultipartData.swift
5 // Created by Tomohiro Kawaji on 12/18/15.
6 // Copyright (c) 2015 Dongri Jin. All rights reserved.
11 public struct OAuthSwiftMultipartData {
13 public var name: String
15 public var fileName: String?
16 public var mimeType: String?
18 public init(name: String, data: Data, fileName: String?, mimeType: String?) {
21 self.fileName = fileName
22 self.mimeType = mimeType
29 public mutating func append(_ multipartData: OAuthSwiftMultipartData, encoding: String.Encoding, separatorData: Data) {
30 var filenameClause = ""
31 if let filename = multipartData.fileName {
32 filenameClause = " filename=\"\(filename)\""
34 let contentDispositionString = "Content-Disposition: form-data; name=\"\(multipartData.name)\";\(filenameClause)\r\n"
35 let contentDispositionData = contentDispositionString.data(using: encoding)!
36 self.append(contentDispositionData)
38 if let mimeType = multipartData.mimeType {
39 let contentTypeString = "Content-Type: \(mimeType)\r\n"
40 let contentTypeData = contentTypeString.data(using: encoding)!
41 self.append(contentTypeData)
44 self.append(separatorData)
45 self.append(multipartData.data)
46 self.append(separatorData)