You need to sign in to do that
Don't have an account?
Filikin
Move chatter files automatically to sharepoint
Hi,
I have the Sharepoint files connector working, so my users can use chatter to browser files in Sharepoint.
I want them to upload files to chatter and for the file to be automatically moved into Sharepoint (at this stage I don't really care where in Sharepoint, I just want to make use of its cheaper file storage).
Does anyone have any apex code that uploads files to Sharepoint - or is there an easier way to do this?
I have the Sharepoint files connector working, so my users can use chatter to browser files in Sharepoint.
I want them to upload files to chatter and for the file to be automatically moved into Sharepoint (at this stage I don't really care where in Sharepoint, I just want to make use of its cheaper file storage).
Does anyone have any apex code that uploads files to Sharepoint - or is there an easier way to do this?
I have solved it myself after a long research. The solution is to get connected to SharePoint Online with OAuth and leverage the power of SharePoint 2013 REST APIs. Features covered:
- Get authenticated
- Upload files with metadata
- Retrieve Files with metadata
- check permissions
For complete information on the same please refer to the below blog:http://spshell.blogspot.in/2015/03/sharepoint-online-o365-oauth.html
For complete SharePoint reference check with the below link:
http://spshell.blogspot.in/2015/01/sharepoint-2013-rest-api-reference.html
https://success.salesforce.com/answers?id=90630000000gtfLAAQ
Please mark this post as solved if it helps.
Best Regards,
Nagendra.P
I am probably missing something, but I feel it should be possible to do this with the file connect API
From what I have read so far, this should work:
String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
String url = salesforceHost + '/services/data/v37.0/connect/content-hub/repositories/0XC4E0000004Cl2WAE/folders/list:L3NpdGVzL3Byb2plY3Rz:23a5ad1f-0d48-4049-a1b1-9d320a2dd5dd:a2ea1803-73f1-43e1-8f59-2e781ae240c2/items';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(url);
req.setHeader('Content-type', 'multipart/form-data; boundary=ArsfGT67minsdfhDSDFHHy987');
req.setHeader('Accept', 'application/json');
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
string body = '--ArsfGT67minsdfhDSDFHHy987\n';
body += 'Content-Type: application/json; charset=UTF-8\n';
body += 'Content-Disposition: form-data; name="json"\n';
body += '{';
body += '"itemTypeId" : "item:L3NpdGVzL3Byb2plY3Rz:23a5ad1f-0d48-4049-a1b1-9d320a2dd5dd:a2ea1803-73f1-43e1-8f59-2e781ae240c2:0x0101",';
body += '"fields" : [{ "name" : "name", "value" : "Created via Files Connect REST API from apex.txt" }]}\n';
body += '--ArsfGT67minsdfhDSDFHHy987\n';
body += 'Content-Disposition: form-data; name="fileData"; filename="HelloSharepoint.txt"\n';
body += 'Content-Type: application/octet-stream; charset=ISO-8859-1\n';
body += '[HELLO from APEX!!!]\n';
body += '--ArsfGT67minsdfhDSDFHHy987--\n';
req.setBody (body);
Http http = new Http();
HTTPResponse res = http.send(req);
but I get a "Bad Request" error when I try it.
However without the content part, it successfully creates an empty file in SharePoint, so I think I am on the right track.
I will persist for a bit longer, but at least now I have something to fall back on.
regards,
Filikin
Please mark this post as solved if it helps.
Best Regards,
Nagendra.P