通过iOS将附件发送到Salesforce Native Rest SDK [英] Send attachments to salesforce native rest sdk through ios

查看:48
本文介绍了通过iOS将附件发送到Salesforce Native Rest SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过iPhone应用程序将图像发送给Salesforce.转换 image->字节-> base64编码,然后存储sfdc(Rich数据字段),这做得很完美,但是我需要另存为图像.这是下面给出的My Codes(不是在职的)指导我如何实现

I need to send my image to salesforce through my iphone app.I have tried those things converted the image--> bytes-->base64 encoding then store the sfdc (Rich data field), it's done perfectly, but i need save as an image .Here are My codes given below (it's not working) Guides me how to achieve that

   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 for 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];

处理我的请求是否需要任何类(Apex)?

Is there any class(Apex) needed to process my request?

推荐答案

我创建了顶点休息类来接收二进制数据,然后将其保存到SFDC(保存在Documents中的图像).这里是我引用的教程.

I have created apex rest classes to recieve the binary data and then save to SFDC (image saved in Documents).Here are the tutorial i referred .

http://blogs.developerforce.com/developer-relations/2011/09/using-binary-data-with-rest.html

这也是教程如何通过我的ios访问apex Web服务.

Also here are the tutorial How to access the apex webservice through my ios.

http://techblog.appirio.com/2013/07/rest-with-apex-service-in-native-ios.html

这篇关于通过iOS将附件发送到Salesforce Native Rest SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆