The "tag_list" array is my issue. As it can be null. And even when I convert it to an empty array in JSON (eg.[]), it still inserts that as a string.
var multipartBody: [Moya.MultipartFormData]? {
switch self {
case .update(_, _, let parametersDict, _):
var formData: [Moya.MultipartFormData] = []
if let parameters = parametersDict {
for (key, value) in parameters {
if value is [String] {
let parameterArray = value as! [String]
if parameterArray.count > 0 {
let jsonArr = try? JSONEncoder().encode(value as! [String])
formData.append(Moya.MultipartFormData(provider: .data(jsonArr!), name: key))
} else {
let emptyArr = try? JSONEncoder().encode(value)
formData.append(Moya.MultipartFormData(provider: .data(emptyArr), name: key))
}
} else {
let valueData = (value as AnyObject).data(using: String.Encoding.utf8.rawValue) ?? Data()
formData.append(Moya.MultipartFormData(provider: .data(valueData), name: key))
}
}
}
Multipart seems less forgiving vs. a "Content-Type": "application/json" format.
I'm trying to send the following dictionary within a multipart form:
The
"tag_list"
array is my issue. As it can be null. And even when I convert it to an empty array in JSON (eg.[]
), it still inserts that as a string.Multipart seems less forgiving vs. a
"Content-Type": "application/json"
format.