如何使用以下方法发布一系列图片

时间:2017-05-13 11:32:29

标签: ios arrays url post swift3

我正在使用Swift 3并希望使用此方法发布图片数组 - 请帮助我该怎么做

if let imageData = UIImageJPEGRepresentation(customKindImage.image! , 1) {
  print("There is Not Any Images to upload!")

  let uploadScriptUrl = URL(string : "http://www.swiftdeveloperblog.com/http-post-example-script/")
  var request = URLRequest(url: uploadScriptUrl!)
  request.httpMethod = "POST"
  request.setValue("Keep-Alive" , forHTTPHeaderField : "Connection")

  let task = URLSession.shared.uploadTask(with: request, from: imageData, completionHandler: { (data, response, error) in
      guard let _ = data, error == nil else {
          print(error?.localizedDescription ?? "Error")
          return
      }
      //access data here
  })            
  task.resume()
}

这是我的数组

var photoes : [UIImage] = [
    UIImage(named: "1.jpg")!,
    UIImage(named: "2.jpg")!,
    UIImage(named: "3.jpg")!]

0 个答案:

没有答案