1 MB file upload size limit for WFFM on CD instance
Sitecore Version: 8.0 Update 4
WFFM Version: 8.0 Update 4
Issues:
When uploading files that are roughly larger than 1 MB on WFFM from CD instances. Form couldn't be submitted and got error on the page:
We experienced a technical difficulty while processing your request. Your data may not have been correctly saved.
From the logs, got this warning:
9320 17:56:54 WARN Posted files size exceeds limit
Parameter name: Posted files size
Exception: System.ArgumentException
Message: Posted files size exceeds limit
Parameter name: Posted files size
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.ArgumentCondition(Boolean condition, String argumentName, String message)
at Sitecore.Form.Core.FormDataHandler.GetSerializableControlResults(IEnumerable`1 fields)
at Sitecore.Form.Core.FormDataHandler.ExecuteSaveActions(ID formId, ControlResult[] fields, ActionDefinition[] actions)
at Sitecore.Form.Core.FormDataHandler.ProcessData(ID formID, ControlResult[] fields, ActionDefinition[] actions)
9320 17:56:54 WARN Web Forms for Marketers: an exception: Posted files size exceeds limit
Parameter name: Posted files size has occured while trying to execute an action.
Investigations:
When checked Sitecore source code:
private static void ExecuteSaveActions(ID formId, ControlResult[] fields, ActionDefinition[] actions)
{
if (Context.Site.DisplayMode != DisplayMode.Normal && Context.Site.DisplayMode != DisplayMode.Preview || WebUtil.GetQueryString("sc_debug", (string) null) != null)
return;
if (Settings.IsRemoteActions)
{
EventManager.QueueEvent<WffmActionEvent>(new WffmActionEvent()
{
...
Fields = Enumerable.ToArray<ControlResult>(FormDataHandler.GetSerializableControlResults((IEnumerable<ControlResult>) fields)),
...
});
...
}
else
{
...
}
}
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<ControlResult> <span class="hljs-title">GetSerializableControlResults</span><span class="hljs-params">(IEnumerable<ControlResult> fields)</span>
</span>{
Assert.ArgumentCondition(FormDataHandler.GetUploadedSizeOfAllFiles(fields) < <span class="hljs-number">1000000</span>L, <span class="hljs-string">"Posted files size"</span>, <span class="hljs-string">"Posted files size exceeds limit"</span>);
<span class="hljs-keyword">return</span> ...
}
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">long</span> <span class="hljs-title">GetUploadedSizeOfAllFiles</span><span class="hljs-params">(IEnumerable<ControlResult> fields)</span>
</span>{
<span class="hljs-keyword">long</span> num = <span class="hljs-number">0</span>;
<span class="hljs-keyword">foreach</span> (ControlResult controlResult <span class="hljs-keyword">in</span> fields)
{
PostedFile postedFile = controlResult.Value <span class="hljs-keyword">as</span> PostedFile;
<span class="hljs-keyword">if</span> (postedFile != <span class="hljs-keyword">null</span> && postedFile.Data != <span class="hljs-keyword">null</span>)
num += (<span class="hljs-keyword">long</span>) postedFile.Data.Length;
}
<span class="hljs-keyword">return</span> num;
}
So when it's a "remoteAction"(IsRemoteActions), which means the form is submitted from delivery instance, it validates the total sizes of all files. Here 1000000L is 1 MB.
1 MB seems to be a very small size since nowadays most smartphones take pictures that are mostly 5 MB or even more. And the way it's hard coded in static method make it hard to understand. However I do understand this is due to the consideration of EventQueue table size, but it should be able to be a bit bigger than 1 MB.
Solutions:
Contacted with Sitecore on this one, Sitecore confirmed that it's a bug. Reference number 67853, however nothing is up yet. They provided us with a patch which makes the file size limit configurable from .config files, we are still testing it. If you have the same issue, please contact Sitecore support for the patch before it's publicly available.