You can not do anything about this, I think a is bug or a limitation.
the WebDev 5.1.7 (b2021060314) module is not ready for multipart/form-data and your desired result.
The work around for this is to include a base64 file in your request. Catch it with base64File = request['params']['yourparamname'] and decode it with Base64 class
I know this is marked as solved, but if other stumble here and want some kind of solution, I parse the POST data as we cannot rely on servletRequest. Only thing is that I prepend date and time to the filename
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import os
import re
if request["servletRequest"].getContentType() and request["servletRequest"].getContentType().startswith("multipart/form-data"):
today = system.date.now()
backupTime = system.date.format(today, "yyyy-MM-dd'T'HH_mm_ss")
dataDir = IgnitionGateway.get().getSystemManager().getDataDir()
postdata = bytearray(request["postData"])
separator = '\n'
if postdata.index('\r\n') < postdata.index(separator):
separator = '\r\n'
boundary = postdata.split(separator, 1)[0]
splitGroups = postdata.split(boundary)
index = 0
length = 0
lenBoundary = len(boundary)
lenSeparator = len(separator)
for g in splitGroups:
sub = g.split(separator * 2, 1)
index = index + len(sub[0]) + 2 * (lenSeparator if len(sub) > 1 else 0)
if "filename=\"" in sub[0] and len(sub) > 1:
p = re.search("filename=\"([^\"]*)\"", sub[0])
filepath = os.path.join(dataDir.getAbsolutePath(), "somesubfolder", "%s-%s" % (backupTime, p.group(1)))
system.file.writeFile(filepath, request["postData"][index:index + len(sub[1]) - lenSeparator])
if len(sub) > 1:
index = index + len(sub[1])
index = index + lenBoundary