美文网首页
Alamofire 上传图片

Alamofire 上传图片

作者: 闲鱼尼克 | 来源:发表于2018-01-10 15:54 被阅读119次
    let address = Service().avatarUrlString()
    let headers = ["authorization": "111111"]
    let imgData = UIImageJPEGRepresentation(uploadImage, 0.2)!

    let URL = try! URLRequest(url: address, method: .post, headers: headers)

    Alamofire.upload(multipartFormData: { (multipartFormData) in
      multipartFormData.append(imgData, withName: "avatar", fileName: "avatar.jpg", mimeType: "image/jpeg")
    }, with: URL) { (result) in
      switch result {
      case .success(let upload, _, _):
        upload.uploadProgress(closure: { (progress) in
          print("Upload Progress: \(progress.fractionCompleted)")
        })
        upload.responseJSON { response in
          print(response)
        }
      case .failure(let encodingError):
        print(encodingError)

      }
    }

相关文章

网友评论

      本文标题:Alamofire 上传图片

      本文链接:https://www.haomeiwen.com/subject/xpmonxtx.html