iphone - Send attachments to salesforce native rest sdk through ios -


i need send image salesforce through iphone app.i have tried things converted image--> bytes-->base64 encoding store sfdc (rich data field), it's done perfectly, need save image .here codes given below (it's not working) guides me how achieve

   nsdata *imagedata = uiimagepngrepresentation(imageview.image);     nsstring *boundary = @"---------------------------14737809831466499882746641449";     sfrestrequest *request = [[sfrestrequest alloc] init];     [request setdelegate:self];     [request setendpoint:ksfdefaultrestendpoint];     [request setmethod:sfrestmethodpost];     nsmutabledata *body = [nsmutabledata data];     [body appenddata:[[nsstring stringwithformat:@"rn--%@rn",boundary] datausingencoding:nsutf8stringencoding]];     [body appenddata:[[nsstring stringwithstring:[nsstring stringwithformat:@"content- disposition: form-data; name=\"entity_document\"; filename=\"%@\"\r\n",@"test.png"]] datausingencoding:nsutf8stringencoding]];     [body appenddata:[@"content-type:  multipart/form-data\r\n\r\n" datausingencoding:nsutf8stringencoding]];     [body appenddata:[[nsstring stringwithstring:[nsstring stringwithformat:@"description :\"%s\"\r\n","marketing brochure q1 2011"]] datausingencoding:nsutf8stringencoding]];     [body appenddata:[[nsstring stringwithstring:[nsstring stringwithformat:@"keywords :\"%s\"\r\n","marketing,sales,update"]] datausingencoding:nsutf8stringencoding]];     [body appenddata:[[nsstring stringwithstring:[nsstring stringwithformat:@"folderid :\"%s\"\r\n","005d0000001giu7"]] datausingencoding:nsutf8stringencoding]];      [body appenddata:[[nsstring stringwithstring:[nsstring stringwithformat:@"name :\"%s\"\r\n","marketing brochure q1"]] datausingencoding:nsutf8stringencoding]];       [body appenddata:[nsdata datawithdata:imagedata]];     [body appenddata:[[nsstring stringwithformat:@"rn--%@--rn",boundary] datausingencoding:nsutf8stringencoding]];      nsstring *attbody = [nsstring stringwithformat:@"{\"body\" : {\"name\" :[{ \"type\" : \"image/jpeg\", \"image\" : \"%@\"}] } }",body];      [request setpath:[nsstring stringwithformat:@"/v23.0/sobjects/document/"]];     [request setqueryparams:(nsdictionary *)[sfjsonutils objectfromjsonstring:attbody]];     [[sfrestapi sharedinstance] send:request delegate:self]; 

is there class(apex) needed process request?

nsdata *mydata = [[nsdata alloc] init];//init file content

nsstring *b64 = [mydata base64encodedstring];  nsdictionary *fields = @{                          @"name": @"document name.ext",                          @"body": b64,                          @"parentid": recordid                          }; attachmentrequest = [[sfrestapi sharedinstance] requestforcreatewithobjecttype:@"attachment" fields:fields];  [[sfrestapi sharedinstance] sendrestrequest:attachmentrequest failblock:^(nserror *e) {     nslog(@"error"); } completeblock:^(id dict){     nslog(@"uploaded"); }]; 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -