Я пытался использовать приведенный ниже параметр в упомянутом вами проекте github.
// Try using this modified parameter in github project
let parameters = ["user": ["name": "MyTestFile123321",
"description": "My tutorial test file for MPFD uploads"],"profile": ["title": "This is big title"]] as [String : Any]
У меня есть код обновления с [String:Any]
typealias Parameters = [String: Any]
func construct() {
// Change it with it your parameter
let parameters = ["user": ["name": "MyTestFile123321",
"description": "My tutorial test file for MPFD uploads"],"profile": ["title": "This is big title"]] as [String : Any]
let dataBody = createDataBody(withParameters: parameters, media: [mediaImage], boundary: boundary)
}
func createDataBody(withParameters params: Parameters?, media: [Media]?, boundary: String) -> Data {
let lineBreak = "\r\n"
var body = Data()
if let parameters = params {
for (key, value) in parameters {
if let sValue = value as? String {
body.append("--\(boundary + lineBreak)")
body.append("Content-Disposition: form-data; name=\"\(key)\"\(lineBreak + lineBreak)")
body.append("\(sValue + lineBreak)")
}else{
if let dictionaryObj = value as? [String : String] {
for (key, value) in dictionaryObj {
body.append("--\(boundary + lineBreak)")
body.append("Content-Disposition: form-data; name=\"\(key)\"\(lineBreak + lineBreak)")
body.append("\(value + lineBreak)")
}
}
}
}
}
if let media = media {
for photo in media {
body.append("--\(boundary + lineBreak)")
//...
}
}
body.append("--\(boundary)--\(lineBreak)")
return body
}
extension Data {
mutating func append(_ string: String) {
if let data = string.data(using: .utf8) {
append(data)
}
}
}
Надеюсь, это будет полезно длявы.:)