# Webdev upload fail

**URL:** <https://forum.inductiveautomation.com/t/webdev-upload-fail/54451>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [December 26, 2021, 3:47pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451 "2021-12-26T15:47:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![448719222](https://avatars.discourse-cdn.com/v4/letter/4/71e660/32.png) [@448719222](https://forum.inductiveautomation.com/u/448719222)\
**Post date:** [December 26, 2021, 3:47pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/1 "2021-12-26T15:47:15Z")

</div>

```auto
	logger = system.util.getLogger("Webdev Debug")
	from org.eclipse.jetty.server import Request
	from javax.servlet import MultipartConfigElement
	from org.apache.commons.io import IOUtils
	
	basereq = request['servletRequest']
	
	basereq.setAttribute(Request.MULTIPART_CONFIG_ELEMENT, MultipartConfigElement(""))
	system.tag.write('[dhProvider]obj_test_float', basereq.getParts())
	for part in basereq.getParts():
		logger.info("%s - %s" % (part.getName(), part.getSize()))
		logger.info(str(part.getSubmittedFileName()))
		system.file.writeFile(part.getSubmittedFileName(), IOUtils.toByteArray(part.getInputStream()))
		system.tag.write('[dhProvider]Obj_0843',part.getSubmittedFileName())
		system.tag.write('[dhProvider]obj_test_float',1)
	return {'html': '<html><body>Hello World</body></html>'}

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e35773e1780b0c98f1264639811550a8f1fe6adb.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/80e0382275c60a5447a380b26bd9288369196c5f.png)  
After uploading the file, basereq Getparts() is an empty array

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 27, 2021, 1:31am UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/2 "2021-12-27T01:31:42Z")

</div>

Oh no haha, what are you doing? The module does the hard work for you, just use this

```auto
byteArray = request['data']

```

I would also use the **POST** method.

This is the output

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba1a43d2509fd2b201e7550d880cddb40a96fca0.png)

---

<div class="post-metadata">

**Author:** ![448719222](https://avatars.discourse-cdn.com/v4/letter/4/71e660/32.png) [@448719222](https://forum.inductiveautomation.com/u/448719222)\
**Post date:** [December 30, 2021, 3:16am UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/3 "2021-12-30T03:16:47Z")

</div>

> [@jespinmartin1](#):
>
> `byteArray = request['data']`

Bytearray contains a lot of information. How can you only extract the file information uploaded by yourself

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 30, 2021, 1:50pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/4 "2021-12-30T13:50:16Z")

</div>

That _ **is** _ the information uploaded. Write those bytes to a file (as bytes) to see for yourself.

---

<div class="post-metadata">

**Author:** ![448719222](https://avatars.discourse-cdn.com/v4/letter/4/71e660/32.png) [@448719222](https://forum.inductiveautomation.com/u/448719222)\
**Post date:** [December 30, 2021, 2:09pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/5 "2021-12-30T14:09:11Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a4d86d54cc68e1898ea33813157ad1ce8c3b0cf4.png)  
How can I extract the data I want, that is, the following

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 30, 2021, 10:45pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/6 "2021-12-30T22:45:52Z")

</div>

You can not do anything about this, I think a is bug or a limitation.

> [@Decode "multipart/form-data" with WebDev](https://forum.inductiveautomation.com/t/decode-multipart-form-data-with-webdev/41173/6):
>
> Hmm, the bad news is it looks like that `IllegalStateException` isn’t something _you_ can work around (though it’s an easy fix on our side; I’m going to open a ticket).  
> For parsing the data, I don’t see any readily available helper classes that are exposed. If you know the format you’re going to get from the zebra printer, it’s probably reasonable to do your own parsing.

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

---

<div class="post-metadata">

**Author:** ![448719222](https://avatars.discourse-cdn.com/v4/letter/4/71e660/32.png) [@448719222](https://forum.inductiveautomation.com/u/448719222)\
**Post date:** [December 31, 2021, 2:16pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/7 "2021-12-31T14:16:46Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [March 21, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/webdev-upload-fail/54451/8 "2023-03-21T18:12:42Z")

</div>

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

```python
	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

```
