Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to ForceClient to read documents from Salesforce API #62

Open
cmortazavi opened this issue Jan 20, 2023 · 2 comments
Open

Add method to ForceClient to read documents from Salesforce API #62

cmortazavi opened this issue Jan 20, 2023 · 2 comments
Assignees

Comments

@cmortazavi
Copy link

When querying the ContentVersion object, the "VersionData" field that is returned is in the form of a URL such as
"services/data/v56.0/sobjects/ContentVersion/0688c000008XvddAAC/VersionData"

This url is apparently the sObjectBlobRetrieve. See below StackExchange article as well as Salesforce documentation
https://salesforce.stackexchange.com/questions/300845/download-contentversion-versiondata-in-python
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_blob_retrieve.htm

According to Salesforce if a user wants to actually get the File, they need to make a web request to this url like

httpClient.GetByteArrayAsync

This should be a method in the ForceClient class

@anthonyreilly anthonyreilly self-assigned this Jan 20, 2023
@anthonyreilly
Copy link
Owner

Added a few things to 4.0.0-Beta to do this, some usage examples below:

SfContentVersion cv = await client.QuerySingle<SfContentVersion>("SELECT Id,VersionData FROM ContentVersion WHERE ID = '0688W00000kkHmSQAU'");
            SfContentVersion cv2 = await client.GetObjectById<SfContentVersion>(SfContentVersion.SObjectTypeName, "0688W00000kkHmSQAU");

            Stream resultStream = await client.BlobRetrieveStream(SfContentVersion.SObjectTypeName,"0688W00000kkHmSQAU","VersionData");
            Stream resultStream2 = await client.BlobRetrieveStream("/services/data/v50.0/sobjects/ContentVersion/0688W00000kkHmSQAU/VersionData");

            using (MemoryStream memoryStream = new MemoryStream())
            {
                await resultStream.CopyToAsync(memoryStream);
                byte[] binary = memoryStream.ToArray();
            }

@cmortazavi
Copy link
Author

cmortazavi commented Jan 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants