import UIKit import AFNetworkingclass YJRequest: NSObject {//#pragma mark - 上传图片 func uploadImageWithImage(_ imageData: Data){let sessionConfiguration = URLSessionConfiguration.defaultlet manager = AFHTTPSessionManager(sessionConfiguration: sessionConfiguration)manager.responseSerializer.acceptableContentTypes = NSSet(arrayLiteral: "application/json", "text/json", "text/javascript","text/html") as? Set<String>manager.post("", parameters: ["":""], constructingBodyWith: { (formData) inlet formatter = DateFormatter()formatter.dateFormat = "yyyyMMddHHmmss"formatter.timeZone = NSTimeZone.systemlet fileName:String = "\(formatter.string(from: NSDate.init() as Date)).jpg"formData.appendPart(withFileData: imageData, name: "head", fileName: fileName, mimeType: "image/png")}, progress: { (progress) in// }, success: { (task, response) in// print("suceess")}) { (task, error) in// print(error)}} }
举了个最简单的例子,没有任何封装与扩展,仅仅供参考