multipart接收多张图片,使用Alamofire快速上传多张图片

通过在参数中使用'[]'来创建一个图片数组,可以使用Alamofire批量上传多张图片。Swift 3的实现示例中,遍历图片数据数组并将其添加到multipartFormData中,同时还能添加其他请求参数。
摘要由CSDN通过智能技术生成

I'm using the following code to upload a single image to a server:

private static func urlRequestWithComponents(urlString:String, parameters:Dictionary, imageData:NSData?, imageName: String) -> (URLRequestConvertible , NSData) {

// create url request to send

let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!)

mutableURLRequest.HTTPMethod = Alamofire.Method.POST.rawValue

let boundaryConstant = "myRandomBoundary12345";

let contentType = "multipart/form-data;boundary="+boundaryConstant

mutableURLRequest.setValue(contentType, forHTTPHeaderField: "Content-Type")

// create upload data to send

let uploadData = NSMutableData()

if(imageData != nil && imageData?.length != 0) {

// add image

uploadD

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值