提前谢谢.. 在我的应用程序中,我必须将图像上传到服务器,下面是我的代码。代码工作正常,因为我得到了响应,但问题是,在服务器端图像只是黑色的。
sessionid=[[[NSUserDefaults standardUserDefaults] valueForKey:@"SessionID"]objectAtIndex:0];
NSLog(@" ID = %@",sessionid);
NSData *da = [NSData data];
da = UIImagePNGRepresentation(self.Profilepic);
NSString *imgStr = [da base64Encoding];
NSLog(@" %d", imgStr.length);
NSString *serverscriptpath=[NSString stringWithFormat:@"http://c4ntechnology.com/biker/web_services/ws_insert_register3.php?"];
NSString *post =[[NSString alloc] initWithFormat:@"profile_pic=%@&sessionid=%@",imgStr,sessionid];
NSLog(@"post string is :%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"post length is :%@",postLength);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSString *script_path=[NSString stringWithFormat:@"%@",serverscriptpath];
[request setURL:[NSURL URLWithString:script_path]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"%@",script_path);
NSData *serverReply = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString* responseString = [[[NSString alloc] initWithData:serverReply encoding: NSUTF8StringEncoding] autorelease];
NSDictionary *dict = [responseString JSONValue];
NSLog(@"%@",dict);
[self ReceivedResponse:dict];
-(void)ReceivedResponse:(NSDictionary *)d
{
[AlertHandler hideAlert];
NSLog(@"%@",d);
}
请任何人都可以帮我找出问题,为什么服务器上的图像是黑色的。?我正在使用 NSDatAdditions.h 文件转换为 base64。
当我使用
NSData *imageData = UIImageJPEGRepresentation(Profilepic, 1.0);
在服务器端,文件不支持发生,所以我使用
NSData *da = [NSData data];
da = UIImagePNGRepresentation(self.Profilepic);