10

I would like to be able to upload files using <lightning:fileUpload which is on a public community page.

The community is using template: Customer Account Portal.

The files would get attached to a custom Questionnaire object.

What are the minimum permissions required on the custom Questionnaire object for the Questionnaire profile & user to be allowed to upload files via a public community page?

enter image description here

I've given the Guest Profile & User full permissions over the custom Questionnaire object and it still errors:

There was a problem uploading your file. Please try again

And nothing appears in the Debug log.

Note: I mistakenly tested the public community using the same browser that I was logged in as Sys Admin, and it uploaded fine. But having tested again using Incognito mode, it does not upload.

  • Is this a customer or a partner community? – Folkert Jul 4 '18 at 13:31
9
+50

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.

enter image description here

5
+100

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

  1. Create Content Deliveries
  2. Create Public Links
  3. 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.

enter image description here

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.

enter image description here

  • May I know how can we relate the file to any record which is uploaded by the guest user? – gold Feb 14 at 17:52
  • I am trying to achieve same functionality. I have created a custom object and gave permissions to guest user profile to it. Created a ltg fileupload component and it works perfectly fine for logged in user. I have enabled to guest site file upload settimg as well. When i try in incognito mode, it still gives me ‘cant upload filename.ext’ error. What else could i be missing? I am using custom template in communities and i have enterprise edition license. Thanks Nike – N Shah Feb 17 at 10:15
1

As pointed out by Jayant Das.

As of Salesforce Spring ’19 Release you can now enable Allow site guest users to upload files

enter image description here

Reference

  • 1
    I was assuming this would fix the issue, but yet it's not working, we expect the same 'Can't upload xyz file' error. I have a opened case with Salesforce and they're still working on figuring out what is needed to enable the feature for guest community user. would come back here to update if I get a positive feedback. – Pasan Eeriyagama Aug 28 at 3:10
  • @PasanEeriyagama did you get a response on this? It works for me if I grant Read Only sharing to the record but I really don't want to have to do this as I don't know the record the guest is trying to access before hand, and on top of that, its not mentioned in the docs! – ministe2003 Oct 23 at 9:39
  • Hi @ministe2003 yes, in my scenario, simply included 'With sharing' in class definition and that fixed the issue for me. cheers! – Pasan Eeriyagama Oct 23 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.