What are permissions are needed to upload a file via a public Salesforce community page?
UPDATE
The component is now supported for guest users with Spring '19.
Let Community Guest Users Upload Files release notes.
Promote file sharing in your communities. Let guest users upload files using the
lightning:fileUpload
component.From documentation for the component:
By default, guest users can’t upload files. You can enable the org preference
Allow site guest users to upload files
.
This section was relevant in Winter '19, removed now as the support is now available with Spring '19.
Based on the latest updated question.
lightning:fileUpload
is not supported for Guest Users. Refer to the below excerpt from documentation.
Guest users can't add files to Communities.
Your only option here may be to utilize a VF page (as mentioned by Pranay in the other answer)
The documentation for lightning:fileUpload
mentions the following:
File uploads are always associated to a record, hence the recordId attribute is required
And based on the help article, if you need to attach a file to a record, you will at least need a READ access on the object.
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.