Resolved Uploading Files From Salesforce To SharePoint Using REST API With Special Characters In Filename

Scenario or Situation

While addressing a requirement for a packaging solutions client in Atlanta, Georgia, there was a need to enable Salesforce users to upload documents from Salesforce entities.

To overcome Salesforce’s storage limitations, uploaded documents are stored in SharePoint.

Challenge or Obstacle

We’ve successfully implemented file upload functionality from Salesforce to SharePoint by developing a custom Lightning web component. We relied on SharePoint REST APIs for direct uploading from Salesforce to SharePoint.

Yet, we encountered an issue while attempting to upload files containing special characters, which led to an error.

Resolution or Solution

Despite multiple attempts with various solutions, we couldn’t resolve the issue. After persistent efforts, we opted for a straightforward JavaScript function that encodes the provided file name. Subsequently, we uploaded it to SharePoint using REST APIs with the same encoded name, and this method successfully resolved the problem. Below is a sample of the implementation:

var updatedFileName = encodeURIComponent(;
var url1 = '' + "/_api/web/GetFolderByServerRelativePath('/Sites//SFUpload/Document Library')/Files/AddUsingPath(overwrite=true,decodedurl='" + updatedFileName + "')";

Conclusion or Summary

By encoding the file name, we have successfully managed to upload a file with special characters from Salesforce to SharePoint.