您的位置:首页 > 移动开发 > IOS开发

ios-上传图片到后台

2014-09-17 11:45 246 查看
做第一个项目时,有个版块的个人信息的编辑涉及到头像修改,老大说项目里有通用的代码,让我自己去找。总算找到,搞了许久才弄好,看来理解能力还需要提高啊!!

#pragma mark- 图像上传保存
- (void)uploadDepartmentLogo//上传部门logo图片
{
NSString *fileName = @"departMentLogo.jpg";
UIImage *image1 = self.headImageView.image;
NSData *data;
if ( UIImagePNGRepresentation(image1) == nil )
{
data = UIImageJPEGRepresentation(image1, 1);
fileName = @"departMentLogo.png";
} else {
data = UIImagePNGRepresentation(image1);
fileName = @"departMentLogo.jpg";
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:fileName];
[data writeToFile:fullPathToFile atomically:NO];

NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
[array addObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:1] forKey:@"type"]];
[array addObject:[NSDictionary dictionaryWithObject:self.deptId forKey:@"deptId"]];

NSMutableArray *imageArray = [[NSMutableArray alloc]init];
[imageArray addObject:[NSDictionary dictionaryWithObject:fullPathToFile forKey:@"file"]];//deptHead

self.request = nil;
requestType = 2;
self.request = [UPRequest uploadPhotoInfo1:@"dept/uploadPhoto" image:imageArray keyName:@"file" delegate:self params:array];
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: