Note that there are some explanatory texts on larger screens.

plurals
  1. POSending image data to Server using POST method from IPhone
    primarykey
    data
    text
    <p>The shown is an API i got for upload image into server. I don't know how to send userid and image data to sever together.</p> <pre><code>url : base_url + /users/editProfilePic input: as POST userId : user’s id picture : base-64 encoded jpg image (300x300px resolution with 1:1 ratio recommended) output: if failed, { "status": "FAIL", "message": "Some Error, try again" } if success, { "status": "OK", "message": "Profile pic updated..", "url": "http://base_url/images/users/profile_pics/8a21edc7db3f0eab4d6f328e28978aa8.jpg" } </code></pre> <p>Can anybody help me by code that can handle this API. I am a beginner in iphone</p> <p>i wrote a code that i given below that is not working.</p> <pre><code>- (BOOL)uploadImage:(NSData *)imageData filename:(NSString *)filename { NSLog(@"Uploading image data %@",imageData); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; DatabaseManger *objDatabase = [[DatabaseManger alloc] init]; NSMutableDictionary *valDict = [objDatabase getUserDetailsInDictionary]; NSString *usernameString = [valDict objectForKey:@"UserID"]; [objDatabase closeSQLDB]; [objDatabase release]; [pool release]; NSMutableString *URL = [NSString stringWithFormat:@"%@%@",SERVER_URL,PROFILEPICTURE ]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]]; NSString *postData = [[NSString alloc] initWithFormat:@"userId=%@&amp;picture=%@",usernameString,imageData]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]]; [postData release]; NSError *error; NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; // parse data from sever by JSON NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSDictionary * PostCommentStaus= ((NSDictionary *)[data JSONValue]); NSLog(@"%@",PostCommentStaus); return ([data isEqualToString:@"OK"]); [data release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload