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
eddieeddie 

Pushing a file to sf

Im looking to attach a file to an account record.

The Attachment object talks about first converting the file to base64 binary.

Please point me in the right direction toward some examples of sending files to salesforce.com

Thankyou

-GL

GlennWGlennW

Here is a function to convert a file to base64 in VB.NET.   Ping me if you want the C# code.

Private Function getFileBase64String(ByVal objFileName As String) As String

Dim inFile As System.IO.FileStream

Dim binaryData() As Byte

Dim bytesRead As Long

Dim base64String As String = ""

inFile = New System.IO.FileStream(objFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)

ReDim binaryData(inFile.Length)

bytesRead = inFile.Read(binaryData, 0, inFile.Length)

inFile.Close()

base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length)

Return base64String

End Function

Cheers;
GlennW
www.demandtools.com

zakzak
If you're coding in .NET, then the SOAP stack will handle the base64 conversion for you, just read your file into an array of bytes, and set the body field to that.