function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YogiBhoiYogiBhoi 

Error in getting salesforce attachment Blob in iOS App?

I am working on salesforce attachment app.This app shows the Attachment list of particular objects like leads,Contacts,opportunity,cases,campaign.

I have successfully uploaded the attachment like images,videos,audio from my app to salesforce account and also download it from salesforce in blob format and show it in my attachment successfully.

For this I have created App on my salesforce account whose name is "salesforce attachment" and generate Consumer key,callback url,Client secrete successfully.

Then I link this consumer key and callback url to my iOS app and I am login successfully.

Now to access the attachment blob,firstly I needed access token.

To get access token I used OAuth 2.0 token flow.
In this I have pass following parameter,
grant_type=password,
client_id=consumerKey,
username=username,
password=password,
Redirect_uri=callbackUrl,

by passing this parameter I have generate access token successfully.

I am using this token every time when I need to get attachment data from salesforce.

Now the problem is that when I login in to my iOS app with my salesforce account on which my salesforce app is created "Salesforce Attachment" my app is working fine.

**But when I login with another salesforce account in my iOS app.I am getting attachment list but not Attachment Blob**

I am getting following error,

{ "message" : "The requested resource does not exist", "errorCode" : "NOT_FOUND" }.

here is my code for getting attachment blob.


NSString *blobPost = [NSString stringWithFormat:@"OAuth %@",access_token];

NSString *urlString=[NSString stringWithFormat:@"%@%@/Body",instance_url,attachmentUrl];

NSURL *blobUrl=[NSURL URLWithString:urlString];

[blobRequest setURL:blobUrl];
[blobRequest setHTTPMethod:@"GET"];
blobRequest setValue:blobPost forHTTPHeaderField:@"Authorization"];
[blobRequest setValue:@"application/pdf" forHTTPHeaderField:@"Content-Type"];

[NSURLConnection
sendAsynchronousRequest:blobRequest
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error)
{

if ([data length] >0 && error == nil)
{

//here i can get attachment data
imageData=[[NSData alloc]initWithData:data];

}
else if ([data length] == 0 && error == nil)
{
NSLog(@"Nothing was downloaded.");
[HUD hide:NO];

}
else if (error != nil){
NSLog(@"Error = %@", error);
}
}];


I need your help.Thanks in advanced

 

listerrrlisterrr

Did you find a solution?

 

I am getting [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

 

It would be great if you share your solution.