【发布时间】:2016-06-23 06:52:45
【问题描述】:
我成功将图像转换为 base64 字符串,但是当我服务到服务器时,服务器得到损坏的数据 我正在使用http://codebeautify.org/base64-to-image-converter# 来获得正确的图像输出
NSString *base64String=[UIImagePNGRepresentation(ProfileImageView.image)
base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];
[base64String stringByReplacingOccurrencesOfString:@"\n\r" withString:@""];
[base64String stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
NSString *post =[[NSString alloc] initWithFormat:@"UserId=%@&UserName=%@&Password=%@&Email=%@&MobileNo=%@&Profiledata=%@",[_DicData valueForKey:@"userId"],[_DicData valueForKey:@"userName"],[_DicData valueForKey:@"password"] ,[_DicData valueForKey:@"email"],MobileNumberLable.text,base64String];
NSString *strurl2=@"api/UpdateUserProfledata/";
NSString *strurl=[NSString stringWithFormat:@"%@%@",_Url1,strurl2];
NSURL *url=[NSURL URLWithString:strurl];
NSData *postData= [post dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *req=[[NSMutableURLRequest alloc]initWithURL:url];
NSString *authtoken=[NSString stringWithFormat:@"ios %@",[_DicData valueForKey:@"authToken"]];
[req setValue:authtoken forHTTPHeaderField:@"Authorization"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:postData];
NSHTTPURLResponse *urlResponse = nil;
NSError *err = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&urlResponse error:&err];
NSLog(@"%@",[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]);
当我从我身边转换图像时,我得到 总字符 =133624 总字数 =0 但是当服务器转换它时 总字符 =133624 总字数 =2891 帮帮我!
.net 中图像转换器的后端代码
公共用户视图模型更新用户配置文件数据(用户视图模型用户更新) { 用户视图模型模型 = 新用户视图模型(); if (userupdate != null && userupdate.UserId > 0) { var getuser = _unitOfWork.UserRepository.GetMany(x => x.UserId == userupdate.UserId).ToList(); 如果 (getuser.Count() > 0) { foreach(getuser 中的 var 项) { item.UserName = userupdate.UserName; item.Email = userupdate.Email; item.MobileNo = userupdate.MobileNo; if (!string.IsNullOrEmpty(userupdate.Profiledata)) { var img = GetBytes(userupdate.Profiledata); item.ProfilePhoto = img; } 模型.Profiledata = userupdate.Profiledata.Trim(); _unitOfWork.UserRepository.Update(item); _unitOfWork.Save(); 返回模型; } } } 返回模型; } 静态字节[] GetBytes(字符串 str) { byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); 返回字节; }
【问题讨论】:
标签: ios json uiimage uiimagepickercontroller