2

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.

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"
    }

Can anybody help me by code that can handle this API. I am a beginner in iphone

i wrote a code that i given below that is not working.

- (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=%@&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:&response error:&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];



    }
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Subin Kurian
  • 283
  • 1
  • 6
  • 13
  • Please specify what you mean by not working. Where does the execution seem to stop? What was response/error details from the last call? Also remember that anything after a `return` statement will not get executed. – Joe Aug 10 '12 at 19:20
  • i am not getting image with the imageurl that getting from the server. posting in this way not making a result. it posting no image i think. please give me a correct method. i am getting a blank image instead of i am sending image. – Subin Kurian Aug 10 '12 at 19:42
  • Check this: http://stackoverflow.com/questions/936855/file-upload-to-http-server-in-iphone-programming – Prazi Nov 26 '12 at 18:25

0 Answers0