1.上传图片

3.

//

//  ios23_uploadViewController.h

//  ios23-upload

//

//  Created by  on 13-6-17.

//  Copyright 2013年 __MyCompanyName__. All rights reserved.

//

#import <UIKit/UIKit.h>

#import "ASIHTTPRequest.h"

@interface ios23_uploadViewController : UIViewController<ASIHTTPRequestDelegate>

-(IBAction)upload;

@end


-------------------------------------------------

//

//  ios23_uploadViewController.m

//  ios23-upload

//

//  Created by  on 13-6-17.

//  Copyright 2013年 __MyCompanyName__. All rights reserved.

//

#import "ios23_uploadViewController.h"

#import "ASIHTTPRequest.h"

#import "ASIFormDataRequest.h"

@implementation ios23_uploadViewController

- (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}

#pragma mark - View lifecycle

-(void)upload{

//定义请求的URL地址:

NSString *uploadURL = @"http://172.22.65.2/2012/upload.php";

UIImage *im = [UIImage imageNamed:@"csdn"];//通过path图片路径获取图片

NSData *data = UIImagePNGRepresentation(im);//获取图片数据

/*

ios中获取图片的方法有两种,一种是UIImageJPEGRepresentation ,一种是UIImagePNGRepresentation前者获取到图片的数据量要比后者的小很多。。

*/

NSURL *url = [NSURL URLWithString:uploadURL];

ASIFormDataRequest *aRequest = [[ASIFormDataRequestalloc] initWithURL:url];

[aRequest setDelegate:self];//代理

[aRequest setRequestMethod:@"POST"];

[aRequest addData:data withFileName:@"test.png"andContentType:@"image/png"forKey:@"file"];

//forKey:@"file"

[aRequest addRequestHeader:@"Content-Type"value:@"binary/octet-stream"];//这里的value值需与服务器端一致

[aRequest startAsynchronous];//开始。异步

[aRequest setDidFinishSelector:@selector(headPortraitSuccess)];//当成功后会自动触发 headPortraitSuccess 方法

[aRequest setDidFailSelector:@selector(headPortraitFail)];//如果失败会自动触发 headPortraitFail 方法

//  [aRequest release];

}

-(void)headPortraitSuccess{

NSLog(@"上传成功!");

}

-(void)headPortraitFail{

NSLog(@"上传失败!");

}

//开始request请求

- (void)requestStarted:(ASIHTTPRequest *)request{

NSLog(@"开始请求!");

}

- (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

- (void)viewDidUnload

{

[superviewDidUnload];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

}

- (void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

}

- (void)viewWillDisappear:(BOOL)animated

{

[superviewWillDisappear:animated];

}

- (void)viewDidDisappear:(BOOL)animated

{

[superviewDidDisappear:animated];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

// Return YES for supported orientations

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

@end


ios23-文件上传的更多相关文章

  1. jquery.uploadify文件上传组件

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...

  2. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

  3. Java FtpClient 实现文件上传服务

    一.Ubuntu 安装 Vsftpd 服务 1.安装 sudo apt-get install vsftpd 2.添加用户(uftp) sudo useradd -d /home/uftp -s /b ...

  4. 小兔Java教程 - 三分钟学会Java文件上传

    今天群里正好有人问起了Java文件上传的事情,本来这是Java里面的知识点,而我目前最主要的精力还是放在了JS的部分.不过反正也不麻烦,我就专门开一贴来聊聊Java文件上传的基本实现方法吧. 话不多说 ...

  5. ,net core mvc 文件上传

    工作用到文件上传的功能,在这个分享下 ~~ Controller: public class PictureController : Controller { private IHostingEnvi ...

  6. Web开发安全之文件上传安全

    很长一段时间像我这种菜鸡搞一个网站第一时间反应就是找上传,找上传.借此机会把文件上传的安全问题总结一下. 首先看一下DVWA给出的Impossible级别的完整代码: <?php if( iss ...

  7. AutoIt实现Webdriver自动化测试文件上传

    在运用WebDriver进行自动化测试时,由于WebDriver自身的限制,对于上传文件时Windows弹出的文件选择窗口无法控制,通过在网上查找资料锁定使用AutoIt来控制文件上传窗口. Auto ...

  8. Struts的文件上传下载

    Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...

  9. .JavaWeb文件上传和FileUpload组件使用

    .JavaWeb文件上传 1.自定义上传 文件上传时的表单设计要符合文件提交的方式: 1.提交方式:post 2.表单中有文件上传的表单项:<input type="file" ...

  10. ASP.NET MVC5+EF6+EasyUI 后台管理系统(32)-swfupload多文件上传[附源码]

    系列目录 文件上传这东西说到底有时候很痛,原来的asp.net服务器控件提供了很简单的上传,但是有回传,还没有进度条提示.这次我们演示利用swfupload多文件上传,项目上文件上传是比不可少的,大家 ...

随机推荐

  1. django perm用法

    定义用户model时可以给用户分配权限: class Meta: permissions = (       ("can_mark", "Can mark"), ...

  2. u-boot分析——struct gd_t与struct bd_t

    gd_t和bd_t是u-boot中两个重要的数据结构,在初始化操作很多都要靠这两个数据结构来保存或传递.分别定义在./include/asm/global_data.h和./include/asm/u ...

  3. 17.1 Replication Configuration

    17.1 Replication Configuration 17.1.1 How to Set Up Replication 17.1.2 Replication Formats 17.1.3 Re ...

  4. c++參数传递

    定义: 形參:指出如今Sub 和Function过程形參表中的变量名.数组名,该过程在被调用前.没有为它们分配内存.其作用是说明自变量的类型和形态以及在过程中的作用.形參能够是除定长字符串变量之外的合 ...

  5. jfinal集成spring cxf做webservice服务

    链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...

  6. Python 第九篇:队列Queue、生产者消费者模型、(IO/异步IP/Select/Poll/Epool)、Mysql操作

    Mysql操作: grant select,insert,update,delete on *.* to root@"%" Identified by "123456&q ...

  7. jquery ajax调用返回json格式数据处理

    Ajax请求默认的都是异步的 如果想同步 async设置为false就可以(默认是true) var html = $.ajax({ url: "some.php", async: ...

  8. solr 从零学习开始

    2010-10 目 录 1 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4. ...

  9. Login oracle for external authenticate

    Generally, we can login the oracle by os authentication, if we login os in a remote machine and make ...

  10. 从汇编角度来理解linux下多层函数调用堆栈执行状态

    注:在linux下开发经常使用的辅助小工具: readelf .hexdump.od.objdump.nm.telnet.nc 等,详细能够man一下. 我们用以下的C代码来研究函数调用的过程.  C ...