swift3.0图片保存到沙盒-从沙盒读取图片显示-从沙盒上传到服务器

guard let img = UIImage(named: "aliyun-logo-local") else {
            return
        }
        
        let imgData = UIImageJPEGRepresentation(img,1)
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)[0]
        let imgPath = "\(path)/\("aliyun-logo-local.png")"
        NSData(data: imgData!).write(toFile: imgPath,atomically: true)
        
        let imgView = UIImageView()
        view.addSubview(imgView)
        imgView.frame = CGRect(x: 100,y: 100,width: 100,height: 100)
        DispatchQueue.global().async(execute: {
            let fileImage = UIImage.init(contentsOfFile: imgPath)
            DispatchQueue.main.async(execute: {
                imgView.image = fileImage
            })
        })
        
        //let fileURL = Bundle.main.url(forResource: "aliyun-logo-local",withExtension: "png")
        let searchURL : URL = URL(fileURLWithPath: imgPath)
        Alamofire.upload(
            multipartFormData: { multipartFormData in
                multipartFormData.append(searchURL,withName: "file")
                
        },to: "http://127.0.0.1/upload/upload_file.PHP",encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload,_,_):
                    upload.responseJSON { response in
                        debugPrint(response)
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }
        })

相关文章

Swift 正式开源!Swift 团队很高兴宣布 Swift 开始开源新篇章。自从苹果发布 Swfit 编程语言,就成为了...
快,快,快!动动您的小手,分享给更多朋友! 苹果去年推出了全新的编程语言Swift,试图让iOS开发更简单...
开发者(KaiFaX) 面向开发者、程序员的专业平台! 和今年年初承诺的一样,苹果贴出了Swift语言的源码,...
本文由@Chun发表于Chun Tips :http://chun.tips/blog/2014/12/11/shi-yong-swift-gou-jian-zi-ding-yi...
本文由CocoaChina译者leon(社区ID)翻译 原文:THE RIGHT WAY TO WRITE A SINGLETON 在之前的帖子里聊过...
本文由CocoaChina译者leon(社区ID)翻译 原文:THE RIGHT WAY TO WRITE A SINGLETON 在之前的帖子里聊过...