I'm a little addicted to it now, so a memo
var task: Task {
switch self {
case .hoge(let files):
//files is[Data]
let fileMFDataArray: [MultipartFormData] = files.enumerated().map({ (index, data) in
MultipartFormData(provider: .data(data),
name: "file", //This is the key
fileName: "\(Int(Date().timeIntervalSince1970))\(index)", //UnixTime +Generate file name of index number
mimeType: "multipart/form-data")
})
return .uploadMultipart(fileMFDataArray)
}
}
Don't forget to set the header to ["Content-Type": "multipart / form-data"] and you're done!
Recommended Posts