在iOS中通过POST上传NSData图像
我有一个表单,其中包含一些个人信息和一个图像。我尝试使用此功能在post中保存信息,效果良好:在iOS中通过POST上传NSData图像,ios,objective-c,post,Ios,Objective C,Post,我有一个表单,其中包含一些个人信息和一个图像。我尝试使用此功能在post中保存信息,效果良好: - (void)Inscription:(NSArray *)value completion:(void (^)( NSString * retour))block{ NSOperationQueue *queue = [[NSOperationQueue alloc] init]; NSArray *Param_header = @[@"usern
- (void)Inscription:(NSArray *)value completion:(void (^)( NSString * retour))block{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSArray *Param_header = @[@"username", @"password", @"email",@"first_name", @"last_name",@"image"];
// NSArray *Param_value = @[@"ali", @"aliiiiiiii", @"ali.ali@gmail.com",@"ali",@"zzzzz"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"http:// /Messenger/services/messenger_register"]]];
NSString *aa=[self buildParameterWithPostType:@"User" andParameterHeaders:Param_header ansParameterValues:value];
[request setHTTPBody:[aa dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
[NSURLConnection sendAsynchronousRequest: request
queue: queue
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) {
if (error || !data) {
// Handle the error
NSLog(@"Server Error : %@", error);
} else {
NSError *error = Nil;
id jsonObjects = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
block([NSString stringWithFormat:@"%@", [jsonObjects objectForKey:@"message"]]);
}
}
];
}
不,我想发送拍摄的照片,我先将其转换为NSData:
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *imag= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
imag = [imag scaleAndRotateImage:imag];
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
int maxFileSize = 25*1024;//was 250x1024
NSData *imageData = UIImageJPEGRepresentation(imag, compression);
while ([imageData length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1;
imageData = UIImageJPEGRepresentation(imag, compression);
}
NSData _D_ImageData = imageData;
我试着将其发送到服务器,但图像c'ant无法上传:
[web Inscription:Param_value completion:^(NSString *retour) {
CustomPrpgress.hidden=true;
NSLog(@" eee %@ ",retour);
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:retour message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}];
谁能帮帮我,我是初学者,这是我第一次。谢谢我的代码工作正常,我在php文件中犯了一个错误我的代码工作正常,我在php文件中犯了一个错误