I have 5 ImageView and 5 Buttons based on that I m getting five images and add it into an array.Now I want to POST them to the server with others parameters also like userId,accessToken .
the input structure which my server wants is
{
"user_id":"26",
"images":[{"image_id":"0","image_data":"BASE 64"}],
"access_token":"MQT3NaF4Njk8M3EzwEU9yUZbymM4B9NqAaSmFm8RE8l3S8JQQEpAwFEpz8lASWlUw78IwnYhSCB9R7So"
}
i have made an DAO class in which i have created a method structure to post the data as
-(void)userProfileImagesWithUserId:(NSInteger)userId
Images:(NSMutableArray *)images
accessToken:(NSString *)AccessToken
urlwithString:(NSString *)url
withSuccessCallBack:(ResponseBlock)responseBlock
{
MGMainDAO *mainDao = [MGMainDAO new];
NSDictionary *params = @{@"user_id":[NSNumber numberWithInteger:userId],
@"images":[images mutableCopy],
@"access_token":AccessToken};
[mainDao postRequest:url withParameters:params withCompletionBlock:^(id responseData,NSError *error){
if (!error) {
if ([responseData isKindOfClass:[NSDictionary class]]) {
responseBlock(YES,responseData,nil);
}
}else{
responseBlock(NO,nil,error);
}
}];
}
Now in My view Controller I m calling this method as
MG_UserMultipleImgDAO *userDao = [MG_UserMultipleImgDAO new];
[userDao userProfileImagesWithUserId:userId Images:mainArr accessToken:accessToken urlwithString:[NSString stringWithFormat:@"%@%@",BASE_URL,userImagesPostFix] withSuccessCallBack:^(BOOL Success, NSDictionary *responseData, NSError *error)
this is not working ,It takes Images Array as nil,How can i achieve this.
I m converting my images into NSData as
for (int i = 0; i < _arrImages.count; i++) {
NSData *base64Data = [UIImageJPEGRepresentation([_arrImages objectAtIndex:i],0.5) base64EncodedDataWithOptions:0];
NSString* str = [[NSString alloc] initWithData:base64Data encoding:NSUTF8StringEncoding];
NSString *base64Image = [NSString stringWithFormat:@"(%@,%@%d),", str, @"image", i+1];
[result appendFormat:@"%@", base64Image];
[encodedImages addObject:result];