1

[SEE UPDATE AT BOTTOM] I'm using sfdx and a scratch org to develop/test my app, which uses the lightning:fileUpload component in two separate components (one for browser, the other for mobile).

It was working well in both components, then it stopped working in both (I think) at the same time -- and I wasn't changing any code on those components. When I try to upload, it allows me to select a file, then immediately gives me the error:

[selected filename].jpg upload progress is 0% 
Can't upload [selected filename].jpg

I know that error happens if you don't have a recordId to associate the uploaded file to, but I've verified that my recordId has a value (Conversation.Id) by putting {!v.Conversation.Id} in the markup -- and it's there. I've also tested hard-coding an id (both from my custom object, Conversation, and also from a Contact) into the markup -- still get the error.

I thought maybe there was some org setting that had inadvertently changed, so I tried uploading a file from Chatter -- no problem with that. It works perfectly.

Here's the markup I'm using (the lightning:fileUpload part is the same in the other component where it's failing):

<aura:attribute name="accept" type="List" default="['.jpg', '.jpeg','.png','.gif']"/>
<aura:attribute name="multiple" type="Boolean" default="false"/>
<aura:attribute name="disabled" type="Boolean" default="false"/>
<aura:attribute name="sendDisabled" type="Boolean" default="true"/>
<aura:attribute name="Conversation" type="Object"/>
<aura:attribute name="File" type="Object"/>

<lightning:overlayLibrary aura:id="photoSelector"/>
<aura:registerEvent name="FileUploaded" type="c:FileUploaded"/>
<aura:registerEvent name="SendPic" type="c:SendPic" />

<aura:handler name="SelectFile" event="c:SelectFile" action="{!c.onSelectFile}"/>

<lightning:card>
    <aura:set attribute="title">
            <lightning:icon iconName="utility:photo" size="small" class="icn-orange"/>
            Select Image and Send 
    </aura:set>

    <c:PhotoList Conversation="{!v.Conversation}"/>

    <aura:set attribute="footer">
        {!v.Conversation.Id} <!-- this is here just to prove it's not null -->
        <lightning:layout horizontalAlign="spread" verticalAlign="center">
            <lightning:layoutitem>
                <lightning:fileUpload   
                    name="fileUploader"
                    label= "Upload Image"
                    multiple="{!v.multiple}"
                    accept="{!v.accept}"
                    disabled="{!v.disabled}"
                    recordId="{!v.Conversation.Id}"
                    onuploadfinished="{! c.handleUploadFinished }"/>
            </lightning:layoutitem>
            <lightning:layoutitem>
                <lightning:buttonGroup>
                    <lightning:button   label="Cancel" onclick="{!c.cancelModal}"/>
                    <lightning:button   label="Send" variant="brand" disabled="{!v.sendDisabled}" 
                                        iconName="utility:share" iconPosition="right" 
                                        onclick="{!c.SendImage}"/>
                </lightning:buttonGroup>
            </lightning:layoutitem>
        </lightning:layout>
    </aura:set>
</lightning:card>

And here's the handleUploadFinished function -- though it never gets that far:

 handleUploadFinished : function(component, event, helper)
 {
    console.log(component.get("v.Conversation").Id);
    var uploadedFiles = event.getParam("files");
    // alert("Files uploaded : " + uploadedFiles.length);
    var thisFile = uploadedFiles[0];
    if (thisFile.ContentSize > 4900000)
    {
        component.set("v.File", thisFile);
        helper.fireFilesizeError(component, event, helper);
    }
    var fileUploaded = $A.get("e.c:FileUploaded");
    fileUploaded.fire();
 },

The files I'm trying to upload are not especially large (for example, 78 kb), so it's not a filesize issue. Can you spot where I'm going wrong? Or is there some org setting I don't know about?


UPDATE

I deleted some of the files, and as soon as I did, the upload started working again, in both components. So there's nothing wrong with the code. Now the question is... is this a cumulative file size limit? Is this only for scratch orgs, or for all orgs? Is it per user?

1

The default scratch org type when you use force:project:create is basically a Developer Edition, so it has some pretty small limits, including a total of 50 MB of file storage. You should end up with larger limits if you change the scratch org edition to Enterprise in the file config/project-scratch-def.json (I believe it's 250 MB, but I don't have a way to check right now). This is a cumulative limit for files. You can check your used space under Setup > Data Management > Storage Usage. All orgs have some sort of file storage limit. Paid orgs can have their values upped by purchasing additional storage blocks. The basic limits are outlined in Monitor Data and Storage Resources.

6
  • @sfdxfox, thanks! I just checked... I do have my scratch org definition set to Enterprise, but that still only gives me 50 MB of File Storage. At least I know my code isn't causing the problem. – PatMcClellan__c Nov 18 '18 at 20:39
  • do you know the best way to access File Storage Limit and Usage through Apex? I'm researching and seeing a few threads from as far back as 2012. Bob Buzzard is talking about creating a VF page and then scraping it to pull that data. I'm hoping there's a more direct way now... – PatMcClellan__c Nov 18 '18 at 21:14
  • I found instructions on making a cURL call to get the info: help.salesforce.com/articleView?id=000213191&type=1 and I found your post about cURL to Apex: salesforce.stackexchange.com/questions/67867/…. It seems really crazy to have to make an HTTP call to the org you're in to get the info! Also, I'm not sure how I'd handle auth... – PatMcClellan__c Nov 18 '18 at 21:38
  • @PatMcClellan__c In Lightning, you have to do the named credential approach, which means you'll have to set a password for the scratch org and go through a manual process each time. Or, you can try the Visualforce cheat which some people have also put on github (example). Some day maybe we'll have a real way to do this, but that's not today. – sfdcfox Nov 18 '18 at 23:48
  • sorry, I see I messed up your handle above because my hand is so used to typing sfdx! I was hoping to build in a way of disabling uploads when file storage capacity is reached, but I think that's more feature than I need. – PatMcClellan__c Nov 20 '18 at 0:04

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.