When the file is uploaded by community user, By default the file will be shared to the file owner and with the record that is being attached. So the file can't be accessed by internal users. File Owner will have Owner Permission and the record will have Viewer permission
You can query the file using contentDocument object. To make the file available for every one, We need to change the "Sharing Settings" of the file.
To change sharing settings, Open the file which will navigate you to content page. Click Show all for sharing
We can also share the file using apex. To publish a record in shared work space
ContentVersion doc = new ContentVersion();
string input = 'Testing ';
Blob blobInput = Blob.valueOf(before);
doc.Title = title;
doc.PathOnClient = 'xyz';
doc.VersionData = blobInput;
insert doc;
doc = [select ContentDocumentId from ContentVersion where id = :doc.id];
ContentWorkspace shareWorkspace = [select id from ContentWorkspace
where name = :workspaceName limit 1];
ContentWorkspaceDoc docLink = new ContentWorkspaceDoc();
docLink.ContentDocumentId = doc.ContentDocumentId;
docLink.ContentWorkspaceId = shareWorkspace.id;
insert docLink;
To publish a record to Personal Workspace:
ContentVersion doc = new ContentVersion();
string input = 'Testing ';
Blob blobInput = Blob.valueOf(before);
doc.Title = title;
doc.PathOnClient = title;
doc.VersionData = blobInput;
doc.FirstPublishLocationID = UserInfo.getUserId();
insert doc;
Comments
Post a Comment