[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?