swift3.0图片保存到沙盒-从沙盒读取图片显示-从沙盒上传到服务器
2016-11-02 00:00
393 查看
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) } })
相关文章推荐
- OpenCV3.0学习(二)——图片的读取、显示与保存
- 上传图片到服务器,服务器保存并且接收到了,但是必须刷新文件夹或者重新部署文件才能在客户端显示图片
- Unity 场景保存,上传服务器,在下载更新场景 IO读取图片和WWW读取图片比较
- 如何读取保存在数据库中的图片显示在DataGrid中
- 上传图片以二进制插入到数据库,且读取显示
- 图片保存到数据库和从数据库读取图片并显示(C#)
- 上传图片到数据库,读取数据库中图片并显示(C#)
- 如何读取保存在数据库中的图片显示在DataGrid中
- ASP.NET上传图片立即显示(不上传到服务器)
- 如何读取保存在数据库中的图片显示在DataGrid中
- 使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
- 上传图片以二进制插入到数据库,且读取显示
- 上传图片以二进制插入到数据库,且读取显示
- web中,如何读取Word内容(包含表格,但不包含图片)并且显示在页面中或保存进数据库中
- 如何读取保存在数据库中的图片显示在DataGrid中
- 上传图片以二进制插入到数据库,且读取显示
- 图片服务器上图片的管理网站上传与前台显示
- java+mysql中保存图片及显示上传的图片struts+hibernate
- web中,如何读取Word内容(包含表格,但不包含图片)并且显示在页面中或保存进数据库中
- 图片保存到数据库和从数据库读取图片并显示(C#)