Alamofire 4.0 / Swift 3.0 - 附加多部分表单数据(CSV文件)

时间:2016-10-20 00:22:25

标签: post swift3 alamofire

我以前在Swift 2.2中使用.post多形式上传,其格式如下(请注意,我不包括所有AlamoFire代码......这太长了。我' m只包括相关部分):

let data = mailStringArray[i].dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
csvDataArray.append(data!)

self.alamoFireManager.upload(.POST, "INSERT URL HERE", headers: header, multipartFormData: { multipartFormData in

multipartFormData.appendBodyPart(data: csvDataArray[0], name: "bulk", fileName: "multi-input.csv", mimeType: "text/csv")

这完美无缺。但是,在迁移到Swift 3.0和Alamofire 4.0之后,我现在使用以下格式:

let data = String(mailStringArray[i]).data(using: String.Encoding.utf8, allowLossyConversion: false)
            csvDataArray.append(data! as NSData)

 self.alamoFireManager.upload(multipartFormData:{ multipartFormData in

multipartFormData.append(csvDataArray[0], withName: "bulk", fileName: "multi-input.csv", mimeType: "text/csv")

usingThreshold:UInt64.init(),
                             to:"INSERT URL HERE",
                             method:.post,
                             headers:["Authorization": "INSERT TOKEN HERE"],
                             encodingCompletion: { encodingResult in

我最终收到以下错误:无法使用类型'(NSData,withName:String,fileName:String,mimeType:String)的参数列表调用参数append'

我正在思考它,因为在Swift 3.0中我不能再发布带有mimetype" text / csv" ......的NSData,但我并不完全确定。

任何帮助都会很棒。谢谢!

1 个答案:

答案 0 :(得分:0)

尝试

multipartFormData.append(csvDataArray [0] as Data ,withName:" bulk",fileName:" multi-input.csv",mimeType:& #34;文本/ CSV&#34)