Attempt 1:
As it was not possible via profiles, I tried doing it via permission set.
I created a new permission set and added below permission for files
- Create Content Deliveries
- Create Public Links
- Moderate Communities Files
And when I tried to assign that permission set to the guest site user, here is the error I get.
It didn't let me assign permission set till I removed all the above 3 permissions.
Can't save permission set AA, which is assigned to a user with user license Guest User License. The user license doesn't allow the permission: Create Content Deliveries
Can't save permission set AA, which is assigned to a user with user license Guest User License. The user license doesn't allow the permission: Create Public Links
Can't save permission set AA, which is assigned to a user with user license Guest User License. The user license doesn't allow the permission: Moderate Communities Files
Salesforce is not willing to allow Files via guest user context and hence it will fail with all the standard methods possible.
Attempt 2:: If I cannot use lightning, let me revert back to visualforce page.
I created a Page and VF controller:
<apex:page controller="ContentController">
<apex:form>
<apex:inputFile value="{!file}" />
<apex:commandbutton action="{!upload}" value="Upload" />
</apex:form>
</apex:page>
Controller:
public class ContentController {
public blob file { get; set; }
public PageReference upload() {
ContentVersion v = new ContentVersion();
v.versionData = file;
v.title = 'testing upload';
v.pathOnClient ='/somepath.txt';
insert v;
return new PageReference('/' + v.id);
}
}
And then used my Community builder to drag and drop that VF page on my Guest access site. I assigned VF page and controller access via Guest User Profile. I published it and then tested in an incognito window
And voila, I was able to upload file and generate an ID for it using visualforce and Apex.
Only Drawback: Less than 6MB can only be uploaded. Happy days.