0

I have successfully uploaded image using the following code

NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"background.png"], 1);
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForUploadFile:data name:@"image.jpeg" description:@"mobile App" mimeType:@"image/jpeg"];

[[SFRestAPI sharedInstance] sendRESTRequest:request failBlock:^(NSError *err){
    NSLog(@"upload error:%@", err.description);
} completeBlock:^(id response){

    NSLog(@"upload Complete = %@", response);
}];

Now i have no idea where am i uploading this image. Saw this on a code snippet that this api uploads image to Chatter Repo.

I have to send some images or videos with every record on salesforce. and some person in the backend should be able to check the record and the images and videos associated with the record.

0

The requestForUploadFile:data method uploads the file to "Chatter Files". It does not associate the file with a chatter feed. You would need to do this in a second call, as described in this post

https://developer.salesforce.com/blogs/developer-relations/2014/03/building-a-native-ios-photo-sharing-app-on-salesforce1-mbaas.html

It sounds like you want to upload images and videos in the context of a record, not chatter. If so you should upload them as attachments.

NSString *recordId = @"00Qo0000001hiGa";

NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"background.png"], 1);
NSString *b64 = [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];

NSDictionary *fields = @{
                         @"Name": @"background.png",
                         @"Body": b64,
                         @"ParentId": recordId
                         };
SFRestRequest *request  = [[SFRestAPI sharedInstance] requestForCreateWithObjectType:@"Attachment" fields:fields];

[[SFRestAPI sharedInstance] sendRESTRequest:request failBlock:^(NSError *e) {
    NSLog(@"Error");
} completeBlock:^(id dict){
    NSLog(@"Uploaded");
}];
0

It sounds like you are uploading images and videos in the context of a record, not chatter. If so you should upload them as attachments.

write this code for chatter with parentID

let imageData: NSData = UIImageJPEGRepresentation(imageView.image!, 0.1)!
    let b64 = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.EncodingEndLineWithLineFeed)
    print(b64)
    let fields = [
        "Name": "k4",
        "Body": b64,
        "ParentId":objectId
    ]

        SFRestAPI.sharedInstance().performCreateWithObjectType("Attachment", fields: fields, failBlock: { err in
            dispatch_async(dispatch_get_main_queue(), {
                let alert = UIAlertView.init(title: "Error", message: err?.localizedDescription , delegate: self, cancelButtonTitle: "OK")
                alert.show()
            })
            print( (err))
        }) { succes in

        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.