Passed string from the another ViewController is not working with NSUrl - ios

I am getting the PassedUserId value from another view.I can print the value in log. but its not assigning to the url string. Here i am trying to pass the text along with image.
NSString *requestString =[NSString stringWithFormat:#"UserId=%#&CategoryId=%#&Continent=%#&Country=%#&City=%#&Gender=%#&ImageName=%#&AgeRange=%#",PassedUserId,CategoryId,continentTextfield.text,countrytextfield.text,citytextfield.text,gender,imagename,ageTextfield.text];
NSString *url=[NSString stringWithFormat:#"http://192.168.2.4:98/UserImage.svc/InsertFacialImage?%#",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
// Create 'POST' MutableRequest with Data and Other Image Attachment.
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage, 0.2f);
[request addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(#"Ret: %#",returnString);

The first thing I noticed is that you have swapped the two values:
stringWithFormat:#"UserId=%#&CategoryId=%#...",CategoryId,PassedUserId
Could you be more specific about what datatypes the CategoryId and PassedUserId have?
If they're strings, you're doing it right. If they are datatype integer though, you should use %i instead of %#.

Related

How to upload video with Privacy setting unlisted in Youtube

I am uploading video on youtube using this code..
- (void)sendVideoFileMetadata:(NSDictionary *)videoMetadata
error:(NSError **)error
{
[self logDebug:#"Sending file info..."];
NSString *category = videoMetadata[kDDYouTubeVideoMetadataCategoryKey];
NSString *keywords = videoMetadata[kDDYouTubeVideoMetadataKeywordsKey];
NSString *title = videoMetadata[kDDYouTubeVideoMetadataTitleKey];
NSString *desc = videoMetadata[kDDYouTubeVideoMetadataDescriptionKey];
NSString *xml = [NSString stringWithFormat:
#"<?xml version=\"1.0\"?>"
#"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"
#"<media:group>"
#"<media:title type=\"plain\">%#</media:title>"
#"<media:description type=\"plain\">%#</media:description>"
#"<media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">%#</media:category>"
#"<media:keywords>%#</media:keywords>"
#"<media:privacyStatus>unlisted</media:privacyStatus>"
#"</media:group>"
#"</entry>", title, desc, category, keywords];
NSURL *url = [NSURL URLWithString:#"https://gdata.youtube.com/action/GetUploadToken"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request setValue:[NSString stringWithFormat:#"GoogleLogin auth=\"%#\"", self.authorizationToken] forHTTPHeaderField:#"Authorization"];
[request setValue:#"2" forHTTPHeaderField:#"GData-Version"];
[request setValue:#"unlisted" forHTTPHeaderField:#"privacyStatus"];
[request setValue:[NSString stringWithFormat:#"key=%#", self.developerKey] forHTTPHeaderField:#"X-GData-Key"];
[request setValue:#"application/atom+xml; charset=UTF-8" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%u", (unsigned int)xml.length] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:[xml dataUsingEncoding:NSUTF8StringEncoding]];
self.responseData = [[NSMutableData alloc] init];
self.currentConnection = [DDURLConnection connectionWithRequest:request delegate:self];
[self.currentConnection setType:DDYouTubeUploaderConnectionTypePrepare];
// Create error if there were
// problems creating a connection
if (!self.currentConnection)
{
*error = [self createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
description:#"Cannot create connection to YouTube."];
}
}
- (BOOL)uploadVideoFile:(NSURL *)fileURL
error:(NSError **)error
{
NSString *boundary = #"AbyRvAlG";
NSString *nextURL = #"http://www.youtube.com";
NSData *fileData = [NSData dataWithContentsOfFile:[fileURL relativePath]];
_videoFileLength = [fileData length];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#?nexturl=%#", self.uploadURLString, nextURL]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request setValue:[NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary] forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
NSMutableString *bodyString = [NSMutableString new];
// Add token
[bodyString appendFormat:#"\r\n--%#\r\n", boundary];
[bodyString appendString:#"Content-Disposition: form-data; name=\"token\"\r\n"];
[bodyString appendString:#"Content-Type: text/plain\r\n\r\n"];
[bodyString appendFormat:#"%#", self.uploadToken];
// Add file name
[bodyString appendFormat:#"\r\n--%#\r\n", boundary];
[bodyString appendFormat:#"Content-Disposition: form-data; name=\"file\"; filename=\"%#\"\r\n", [fileURL lastPathComponent]];
[bodyString appendFormat:#"Content-Type: application/octet-stream\r\n\r\n"];
[bodyString appendFormat:#"privacyStatus: unlisted\r\n\r\n"];
// Create the data
[body appendData:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:fileData]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// Set the body
[request setHTTPBody:body];
// Create the connection
self.responseData = [[NSMutableData alloc] init];
self.currentConnection = [DDURLConnection connectionWithRequest:request delegate:self];
[self.currentConnection setType:DDYouTubeUploaderConnectionTypeUpload];
if (!self.currentConnection)
{
*error = [self createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
description:#"Cannot create connection to YouTube."];
return NO;
}
return YES;
}
This working perfectly,
But the issue is video uploaded as Public, i want to upload it as Unlisted.
I have tried so many tag but not able to get success.
Used,
- privacy
- privacystatus
Can anyone let me know where should i add the tag and whats the tag?
Code snippet will be more helpful.
Just update xml by adding
<yt.accesscontrol>
and it will uplaoad video as unlisted
NSString *xml = [NSString stringWithFormat:
#"<?xml version=\"1.0\"?>"
#"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"
#"<media:group>"
#"<media:title type=\"plain\">%#</media:title>"
#"<media:description type=\"plain\">%#</media:description>"
#"<media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">%#</media:category>"
#"<media:keywords>%#</media:keywords>"
#"</media:group>"
#"<yt:accessControl action='list' permission='denied'/>"
#"</entry>", title, desc, category, keywords];

How to Send JSON String with Special Charaters in iOS?

I'm new to iOS and i'm using the following code to make API Calls.
-(NSData *)sendDataToServer:(NSString*)url :(NSString*)params
{
NSString *postDataString = [params stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"postDataString :%#",postDataString);
NSData *postData = [postDataString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *urlReq = [NSString stringWithFormat:#"%#", url];
[request setURL:[NSURL URLWithString:urlReq]];
[request setTimeoutInterval:180];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"response in Server: %#",responseString);
return responseData;
}
I'm sending the following string as params to the above method. If I send the following data without special characters, I'm getting the success response.
If i Add any special charters as like (&) with json I'm always getting the invalid response, that is the server always returns null.
So Can anyone please provide any suggestion to get the right response when using json string with Special characters like '&' etc.,
submited_data={"safty_compliance_fields":[{"safty_compliance_id":"641","fieldName":"sc1","fieldType":"editText","fieldValue":"wedgies Ig"},{"safty_compliance_id":"642","fieldName":"sc2","fieldType":"editText","fieldValue":"het &"}],"status_id":"2","product_detail":[{"dynamic_fields_id":"639","fieldName":"p1","fieldType":"editText","fieldValue":"data1"},{"dynamic_fields_id":"640","fieldName":"p2","fieldType":"editText","fieldValue":"data2"}],"inspection_id":"3","second_level":[{"questions":[{"checkListValue":"NO","checkListCommentValue":"Jgkjgjkj","sub_category_id":"452","checkListName":"sl1"},{"checkListValue":"YES","checkListCommentValue":"jk","sub_category_id":"453","checkListName":"sl2"},{"checkListValue":"YES","checkListCommentValue":"gh","sub_category_id":"455","checkListName":"sl3"},{"checkListValue":"YES","checkListCommentValue":"nm","sub_category_id":"456","checkListName":"sl4"}],"title":"sl1","entity_second_level_entry_id":"130"},{"questions":[{"checkListValue":"YES","checkListCommentValue":"Bonn","sub_category_id":"454","checkListName":"s22"}],"title":"s211","entity_second_level_entry_id":"131"}],"comment":"Jgkjgjkj","status":"Ongoing"}
You didn't post the percent encoded string, but the original string.

NSURLSession for sending multiple images by multiple urls

The below code i am using for sending multiple images along with the text. but only one image is saving in Web server. Here the problem is i need to get response from the first url and i've to assign it to the second url.
NSLog(#"PassedID%#",PassedUserId);
NSLog(#"integer=%#", [[NSUserDefaults standardUserDefaults] objectForKey:#"Person"]);
NSString *CategoryId=#"3";
NSString *imagename=#"ComparisonObject";
NSString *requestString =[NSString stringWithFormat:#"UserId=%#&CategoryId=%#&Continent=%#&Country=%#&City=%#&Gender=%#&ImageName=%#",PassedUserId,CategoryId,continentTextfield.text,countrytextfield.text,citytextfield.text,GenderText.text,imagename];
NSLog(#"%#",requestString);
NSString *url=[NSString stringWithFormat:#"http://192.168.2.4:98/UserImage.svc/InsertObjectImage?%#",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *uploadImage1 = [session dataTaskWithRequest:request completionHandler:^(NSData *data2, NSURLResponse *response, NSError *error) {
// Finish uploading image 1
// Get response and data to prepare to update image 2
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage1, 0.2f);
[request addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(#"recievedData%#",receivedData);
NSString *imagename=#"ComparisonObject";
NSString *requestString1 =[NSString stringWithFormat:#"UserId=%#&ImageId=%#&=ImageName%#",PassedUserId,compareId,imagename];
NSLog(#"%#",requestString1);
NSString *url=[NSString stringWithFormat:#"http://192.168.2.4:98/UserImage.svc/UpdateObjectImage?%#",requestString1];
NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
NSURLSessionDataTask *uploadImage2 = [session dataTaskWithRequest:request2 completionHandler:^(NSData *data1, NSURLResponse *response, NSError *error) {
NSLog(#"recievedData%#",receivedData);
NSString *imagename=#"ComparisonObject";
NSString *requestString1 =[NSString stringWithFormat:#"UserId=%#&ImageId=%#&=ImageName%#",PassedUserId,compareId,imagename];
NSLog(#"%#",requestString1);
NSString *url=[NSString stringWithFormat:#"http://192.168.2.4:98/UserImage.svc/UpdateObjectImage?%#",requestString1];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage2, 0.2f);
[request addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
// Finish uploading image 2
}];
}];

Post multiple images into web server

The code make me very happy to Post image into Web server. its working smart for single image. The code what i've to used to Post a single image is
NSLog(#"%#",requestString);
NSString *url=[NSString stringWithFormat:#"http://37.187.152.236/UserImage.svc/InsertFacialImage?%#",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
// Create 'POST' MutableRequest with Data and Other Image Attachment.
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage, 0.2f);
[request addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
Then i failed to jump over the hurdle, Failed to Post 2 images with different services.The truth behind my failure is after uploading of the 1st image, server generate response then i've attach the response to second service. i did it properly but failed because i made the connection run 2 times for 2 images.but Web services team asking me that run it in a single connection.The code which i is used, which i need to modify is
Posting 1st image
NSString *url=[NSString stringWithFormat:#"http://37.187.152.236/UserImage.svc/InsertObjectImage?%#",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
// Create 'POST' MutableRequest with Data and Other Image Attachment.
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage1, 0.2f);
[request addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(#"Ret: %#",returnString);
NSURLConnection *connReq = [NSURLConnection connectionWithRequest:request delegate:self];
if (connReq) {
NSLog(#"Connection Sucessful");
receivedData = [[NSMutableData alloc]init];
}
else {
NSLog(#"failed");
}
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(#"Status code: %ld", (long)[response statusCode]);
Generating Response
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(#"%#" , error);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSError *e;
jsonDict1 = [NSJSONSerialization JSONObjectWithData:receivedData options: NSJSONReadingMutableContainers error: &e];
compareId = [jsonDict1 valueForKey:#"ImageId"];
NSLog(#"JSONN%#" , jsonDict1);
compareId = [results.firstObject objectForKey:#"ImageId"];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.compareId forKey:#"Sendy"];
[defaults synchronize];
NSLog(#"compareId:%#",compareId);
results = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:&e];
}
}
after this step is response is generating good and i can pass it to the second string. so no problem with the server response.
*Post 2nd Image *
NSString *url1=[NSString stringWithFormat:#"http://37.187.152.236/UserImage.svc/UpdateObjectImage?%#",requestString1];
NSMutableURLRequest *request1 = [[NSMutableURLRequest alloc] init] ;
[request1 setURL:[NSURL URLWithString:url1]];
[request1 setHTTPMethod:#"POST"];
// Create 'POST' MutableRequest with Data and Other Image Attachment.
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request1 setValue:contentType forHTTPHeaderField:#"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage2, 0.2f);
[request1 addValue:#"image/JPEG" forHTTPHeaderField:#"Content-Type"];
NSMutableData *body1 = [NSMutableData data];
[body1 appendData:[NSData dataWithData:data]];
[request1 setHTTPBody:body1];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(#"Ret: %#",returnString);
NSURLConnection *connReq = [NSURLConnection connectionWithRequest:request1 delegate:self];
if (connReq) {
NSLog(#"Connection Sucessful");
receivedData = [[NSMutableData alloc]init];
}
else {
NSLog(#"failed");
}
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *respData = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error];
NSLog(#"Status code: %ld", (long)[response statusCode]);

Image not posting by base64 string on json

I am Posting a image on Server By json Post Webservice.I have to upload the image on base 64 .I am encoding my image to base 64 string but the Image is not posting on the server and not other things.There is No problem with the webservice.The image is uploading successfully in android.
selectedImage=[[NSData alloc]initWithData:UIImageJPEGRepresentation(image, 1.0)];
[[NSUserDefaults standardUserDefaults]setObject:selectedImage forKey:#"image"];
[[NSUserDefaults standardUserDefaults]synchronize];
strImage=[[NSString alloc]init];
strImage = [selectedImage base64Encoding];
strImage=[strImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"strImage %#",strImage);
/*
NSData *b64DecData = [Base64 decode:strImage];
NSLog(#"strImage %#",strImage);
[bttnimage setBackgroundImage:[UIImage imageWithData:b64DecData] forState:UIControlStateNormal];
*/
NSString *post=[[NSString alloc]initWithFormat:#"name=%#&aboutMe=%#&chatId=%#&gender=%#&lookingFor=%#&city=%#&birthdate=%#&anniversarydate=%#&number1=%#&number2=%#&number3=%#&image=%#",[txtProfileName.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[txtComment.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[appDelegate.chatid stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[bttnGender.titleLabel.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[bttnLookingfor.titleLabel.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[txtPlace.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[dobLabel.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[anniversaeyLabel.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[txtNumber.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[txtNum1.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[txtNum2.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],strImage];
NSLog(#"post %#",post);
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString * postLength = [NSString stringWithFormat:#"%d",[postData length]];
NSMutableURLRequest *latrequest = [[NSMutableURLRequest alloc] init];
NSString *url=[NSString stringWithFormat:#"http://www.xyzAbc.org/iphone/updateProfile.php?%#",post];
NSLog(#"url %#",url);
[latrequest setURL:[NSURL URLWithString:url]];
Connection=[NSURLConnection connectionWithRequest:latrequest delegate:self];
[latrequest setHTTPMethod:#"POST"];
[latrequest setValue:postLength forHTTPHeaderField:#"Content-Length"];
[latrequest setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[latrequest setHTTPBody:postData];
[latrequest release];
NSLog(#"latre %#",latrequest);
the code is above Please Let me know if I am missing something. Please any one Help me with that.
First add Base64.h and Base64.m files to your project. The following method will return Base-64 string from UIImage.
-(NSString*)getBase64StringfromImage:(UIImage*)image{
NSData *imageData = UIImageJPEGRepresentation(image,90);
NSString *ImgStr=[Base64 encode:imageData];
ImgStr=[ImgStr stringByReplacingOccurrencesOfString:#"+" withString:#"%2B"];
return ImgStr;
}
Image posting is different in iOS when we compare it with Android.
And in iOS do this formate
NSString *urlString = [NSString stringWithFormat:#"********************/web-services/register_user.php?firstname=%#&lastname=%#&email=%#&password=%#&location=india&device=IPHONE",details.fname,details.lname,details.emailAddress,details.password];
// urlString=[urlString stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
UIImage *image=details.pic;
NSData *imageData =UIImageJPEGRepresentation(image, 0.1);
double my_time = [[NSDate date] timeIntervalSince1970];
NSString *imageName = [NSString stringWithFormat:#"%d",(int)(my_time)];
NSString *string = [NSString stringWithFormat:#"%#%#%#", #"Content-Disposition: form-data; name=\"profile_pic\"; filename=\"", imageName, #".jpg\"\r\n\""];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#",boundary];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:string] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString*s11= [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSDictionary *responseDictionary1;
responseDictionary1 = [XMLReader dictionaryForXMLString:s11 error:nil];
////////
This will fix issue
Regards
Charan Giri

Resources