完整版的iphone(XCODE),oc
//保存图片
- (void)saveImage
{
_alertview= [[UIAlertViewalloc]initWithTitle:nil
message:@"正在上传照片..."
cancelButtonTitle:nil
otherButtonTitles:nil];
//加载一个旋转的等待图标
activityView= [[UIActivityIndicatorViewa
activityView.frame=CGRectMake(120.f,48.0f,37.0f,37.0f);//加入等待图标
[_alertviewaddSubview:activityView];
[activityViewstartAnimating];
[activityViewrelease];
[_alertviewshow];
NSURL*url = [NSURLURLWithString:[NSStringstringWithFormat
m_imageData=UIImagePNGRepresentation
//m_imageData = UIImageJPEGRepresentatio
NSData*postDateBoundary = [[NSStringstringWithFormat
NSData*postDateBoundaryEnd = [[NSStringstringWithFormat
NSData*postDateHead = [[NSStringstringWithFormat
@"Content-Disposition: form-data; name="File1\"; filename="a1.jpg"\r\nContent-Type: image/pjpeg\r\n\r\n"]
dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData*postData = [NSMutableDatadataWithCapacity:[m_imageDatalength] ];
[postData
[postData
[postData
[postData
NSMutableURLRequest*urlRequest = [NSMutableURLRequestreque
[urlRequest
[urlRequestsetValue: [NSStringstringWithFormat:@"%@\r\n"
[urlRequestsetValue:[NSStringstringWithFormat
[urlRequestsetValue:[NSStringstringWithFormat:@"multipart/form-data; boundary=---------------------------7da36b1b4045c"]
NSString
[urlRequestsetValue:[NSStringstringWithFormat
[urlRequestsetValue:[NSStringstringWithFormat
[urlRequest
NSURLConnection*theConnection = [[NSURLConnectionalloc]initWithRequest:urlRequestdelegate:self];
if
{
uploadDidSucceed=NO;
_webData= [[NSMutableDatadata]retain];//初始化一个数据流
}
}
//
- (void) connection:(NSURLConnection
{
}
//
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
}
//连接结束
- (void)connectionDidFinishLoadi
{
}
****这个是一个完整的上传组件,只要提供图片数据,剩下的拷贝粘贴就可以了