ios - Prevent Restkit from adding escape characters? -


i trying encode image using base64 encoding , pass through json , generate json request , call restful api using restkit.

what have seen in log restkit adds escape characters encoded image, preventing server end decoding image , fails.

i want know whats best option stop restkit adding escape characters

below example

vpt\/x8wwdcpj1xbpj1zpbduwlhlnpczgnmlx3exaffi0p7nklapgo7hzsmxzc\/xitc\/k4iwrsg 

one can see slashes (\/) added string.

here code m using encoding string

nsdata *originalphoto = uiimagepngrepresentation([uiimage imagenamed:@"time_icon.png"]); nsstring *base64photostring = [base64 encode:originalphoto]; 

base64.m follows

+ (nsstring*) encode:(const uint8_t*) input length:(nsinteger) length {     nsmutabledata* data = [nsmutabledata datawithlength:((length + 2) / 3) * 4];     uint8_t* output = (uint8_t*)data.mutablebytes;      (nsinteger = 0; < length; += 3) {         nsinteger value = 0;         (nsinteger j = i; j < (i + 3); j++) {             value <<= 8;              if (j < length) {                 value |= (0xff & input[j]);             }         }          nsinteger index = (i / 3) * 4;         output[index + 0] =                    encodingtable[(value >> 18) & 0x3f];         output[index + 1] =                    encodingtable[(value >> 12) & 0x3f];         output[index + 2] = (i + 1) < length ? encodingtable[(value >> 6)  & 0x3f] : '=';         output[index + 3] = (i + 2) < length ? encodingtable[(value >> 0)  & 0x3f] : '=';     }      return [[[nsstring alloc] initwithdata:data                                   encoding:nsasciistringencoding] autorelease]; }   + (nsstring*) encode:(nsdata*) rawbytes {     return [self encode:(const uint8_t*) rawbytes.bytes length:rawbytes.length]; } 

i passing encoded string restkit request string

if not wrong stuck @ send image server via restkit. friend try multipart.

in restkit v0.20.3 have few changes. here add code snippet multipart post via rkobjectmanager instance.

nsstring *strtexttopost = self.txtviewforpost.text;     nsmutabledictionary *params = [nsmutabledictionary dictionary];     mediatype ? [params setobject:mediatype forkey:@"media_type"] : @"";     strtexttopost ? [params setobject:strtexttopost forkey:@"post_text"] : @"" ;      nsmutableurlrequest *request = [[appdelegate appdelegate].rkomforpost multipartformrequestwithobject:nil method:rkrequestmethodpost path:strpath parameters:params constructingbodywithblock:^(id<afmultipartformdata> formdata) {         [formdata appendpartwithfiledata:contentdata                                     name:@"file"                                 filename:filename                                 mimetype:filetype];     }];      rkobjectrequestoperation *operation = [[appdelegate appdelegate].rkomforpost objectrequestoperationwithrequest:request success:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult) {         [rsactivityindicator hideindicator];         nslog(@"%@",operation.httprequestoperation.responsestring);     } failure:^(rkobjectrequestoperation *operation, nserror *error) {         [rsactivityindicator hideindicator];         nslog(@"%@",operation.httprequestoperation.responsestring);     }];     [[appdelegate appdelegate].rkomforpost enqueueobjectrequestoperation:operation]; 

enqueueobjectrequestoperation complete multipart operation. try given code. surely works.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -