首页 > 编程语言 > 详细

swift上传图片

时间:2017-02-15 18:37:14      阅读:193      评论:0      收藏:0      [点我收藏+]
import UIKit
import AFNetworking

class YJRequest: NSObject {
    
    //#pragma mark - 上传图片 
    func uploadImageWithImage(_ imageData: Data){

    let sessionConfiguration = URLSessionConfiguration.default
    let 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) in
            let formatter = DateFormatter()
            formatter.dateFormat = "yyyyMMddHHmmss"
            formatter.timeZone = NSTimeZone.system
            let 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)
        }
        
    }
}

 

swift上传图片

原文:http://www.cnblogs.com/yajunLi/p/6393882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!