Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:17:31+00:00 2026-05-27T12:17:31+00:00

I am using RestKit to drive interactions with my web server. I am trying

  • 0

I am using RestKit to drive interactions with my web server. I am trying to use routing to POST an Event object to the server with an image attached to it. The code is as follows:

  RKObjectManager *manager = [RKObjectManager sharedManager];

  RKObjectMapping *map = [self eventMapping];
  manager.serializationMIMEType = RKMIMETypeFormURLEncoded;
  map.rootKeyPath = @"event";
  [manager.mappingProvider setSerializationMapping:map forClass:[Event class]];
  [manager.router routeClass:[Event class] toResourcePath:@"/v1/events.json" forMethod:RKRequestMethodPOST];

  [manager postObject:event delegate:self block:^(RKObjectLoader *loader){
    RKObjectMapping *serMap = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[Event class]];
    NSError *error = nil;
    NSDictionary *d = [[RKObjectSerializer serializerWithObject:event mapping:serMap] serializedObject:&error];

    RKParams *p = [RKParams paramsWithDictionary:d];
    [p setData:[event imageData] MIMEType:@"image/jpeg" forParam:@"image"];
    loader.params = p;
  }];

If I create an instance of RKParams using the serialized Event object, then add the image data and assign it as the RKObjectLoader’s params property, all the properties become one massive serialized string. There must be a way to upload an image without the massive string serialization.

I have also tried having an NSData property that is mapped to some attribute, converting a UIImage into NSData along the way, but RestKit complains that it can’t be mapped. Has anyone done this before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:17:32+00:00Added an answer on May 27, 2026 at 12:17 pm

    I did something very similar and it worked out just fine. I realize your question is about why RKObjectSerializer isn’t working the way you expect, but maybe it is something else with your setup. I’m posting my code to give a clean example of something that does work. That said, after reading the RKObjectSerializer documentation, I don’t see why you couldn’t initialize your RKParams that way instead of setting them directly as I do in my example.

    Router setup:

    RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:kApiUrlBase];
    [objectManager.router routeClass:[PAPetPhoto class] toResourcePath:@"/pet/uploadPhoto" forMethod:RKRequestMethodPOST];
    

    Mapping setup:

    RKObjectMapping *papetPhotoMapping = [RKObjectMapping mappingForClass:[PAPetPhoto class]];
    [papetPhotoMapping mapKeyPath:@"id" toAttribute:@"identifier"];
    [papetPhotoMapping mapAttributes:@"accountId", @"petId", @"photoId", @"filename", @"contentType", nil];
    [objectManager.mappingProvider addObjectMapping:papetPhotoMapping];
    [objectManager.mappingProvider setSerializationMapping:[papetPhotoMapping inverseMapping] forClass:[PAPetPhoto class]];
    [objectManager.mappingProvider setMapping:papetPhotoMapping forKeyPath:@"petPhoto"];
    

    The post: (notice since I built up all my params in the block my object is just a dummy instance to trigger the proper routing and mapper).

        PAPetPhoto *photo = [[PAPetPhoto alloc] init];
        [[RKObjectManager sharedManager] postObject:photo delegate:self block:^(RKObjectLoader *loader){
    
            RKParams* params = [RKParams params];
            [params setValue:pet.accountId forParam:@"accountId"];
            [params setValue:pet.identifier forParam:@"petId"];
            [params setValue:_photoId forParam:@"photoId"];
            [params setValue:_isThumb ? @"THUMB" : @"FULL" forParam:@"photoSize"];
            [params setData:data MIMEType:@"image/png" forParam:@"image"];
    
            loader.params = params;
        }];
    

    Server endpoint (Java, Spring MVC)

        @RequestMapping(value = "/uploadPhoto", method = RequestMethod.POST)
        @ResponseBody
        public Map<String, Object> handleFormUpload(@RequestParam("accountId") String accountId,
                                        @RequestParam("petId") String petId,
                                        @RequestParam("photoId") String photoId,
                                        @RequestParam("photoSize") PhotoSizeEnum photoSize,
                                        @RequestParam("image") Part image) throws IOException {
    
            if (log.isTraceEnabled()) 
                log.trace("uploadPhoto. accountId=" + accountId + " petId=" + petId + " photoId=" + photoId + " photoSize=" + photoSize);
    
            PetPhoto petPhoto = petDao.savePetPhoto(accountId, petId, photoId, photoSize, image);
    
            Map<String, Object> map = GsonUtils.wrapWithKeypath(petPhoto, "petPhoto");
            return map;
        }
    

    Server response JSON (note the keyPath of “petPhoto” that corresponds to the mapping setup):

    {
        petPhoto =     {
            accountId = 4ebee3469ae2d8adf983c561;
            contentType = "image/png";
            filename = "4ebee3469ae2d8adf983c561_4ec0983d036463d900841f09_3FED4959-1042-4D8B-91A8-76AA873851A3";
            id = 4ee2e80203646ecd096d5201;
            petId = 4ec0983d036463d900841f09;
            photoId = "3FED4959-1042-4D8B-91A8-76AA873851A3";
        };
    }
    

    Delegate:

    - (void) objectLoader:(RKObjectLoader*)objectLoader didLoadObject:(id)object {
    
        if ([objectLoader wasSentToResourcePath:@"/pet/uploadPhoto"]) {
           PAPetPhoto *photo = (PAPetPhoto*)object;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a RestKit request to load an image from a web
I have a small app using RestKit with a Sinatra-backed server. When I post
When I try to post an object using RestKit I get the following error.
On iOS 5, how can I query a web service using a JSON object?
I was using https://github.com/RestKit/RestKit/wiki/Using-Multiple-Base-URLs-%28and-Multiple-Object-Managers%29 as a guide. I know it's possible to create multiple
I am using RESTKIT to map the JSON returned from server. The JSON result
I'm trying to get the JSON format string from my custom object by using
I'm using RestKit to develop a RESTful application. I have a wrapper object that
I'm trying to integrate the Rack OAuth-2 server into my sinatra application, to use
Using PyObjC , you can use Python to write Cocoa applications for OS X.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.