# Webdev image upload?

**URL:** <https://forum.inductiveautomation.com/t/webdev-image-upload/15704>\
**Category:** Ignition\
**Created:** [October 18, 2017, 2:36pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704 "2017-10-18T14:36:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [October 18, 2017, 2:36pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/1 "2017-10-18T14:36:29Z")

</div>

Hi all,

Has anyone tried to use webdev to receive a file and store it into a database? Just curious as to how this group would go about it.

Thanks,

Oscar.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 18, 2017, 3:33pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/2 "2017-10-18T15:33:10Z")

</div>

I would start from the simplest possible case: an [HTML form](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) accepting a ‘File’ input, which would then pass the file data (probably either b64 encoded or as a bytestream) to a different endpoint.

---

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [October 18, 2017, 5:35pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/3 "2017-10-18T17:35:57Z")

</div>

Thanks @paul-griffith!

The posting side is sorted out; the data is actually coming from a “Google Glass”-type device that will complete an action in an Augmented Reality environment, and post the results of the action (which includes an image) to the Webdev endpoint.

My question was more about how to process that file stream coming into Webdev using Scripting. If anyone has any examples that would be great.

Thanks.  
Oscar.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 18, 2017, 10:09pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/4 "2017-10-18T22:09:41Z")

</div>

My test setup was this, on a single `/upload` endpoint.  
doGet:

```auto
	html = """<html><head></head></body>
	<form method="POST" enctype="multipart/form-data">
		<input type="file" name="filename"><br>
		<input type="submit" value="Submit">
	</form>"""
	return {'html': html}

```

doPost:

```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(""))
	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()))

	return {'html': '<html><body>Hello World</body></html>'}

```

---

<div class="post-metadata">

**Author:** ![djones](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@djones](https://forum.inductiveautomation.com/u/djones)\
**Post date:** [December 9, 2020, 11:26pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/5 "2020-12-09T23:26:14Z")

</div>

I implemented the code above but receive the following:

```auto
## HTTP ERROR 500 Traceback (most recent call last): File "<GE_Time_Tracker/python:doPost>", line 11, in doPost AttributeError: type object 'org.eclipse.jetty.server.Request' has no attribute '__MULTIPART_CONFIG_ELEMENT'

|URI:|/system/webdev/GE_Time_Tracker/python|
| --- | --- |
|STATUS:|500|
|MESSAGE:|Traceback (most recent call last): File "<GE_Time_Tracker/python:doPost>", line 11, in doPost AttributeError: type object 'org.eclipse.jetty.server.Request' has no attribute '__MULTIPART_CONFIG_ELEMENT'|
|SERVLET:|Map|

```

I cannot seem to figure out where i am going wrong with implementing this

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2020, 11:33pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/6 "2020-12-09T23:33:06Z")

</div>

Looks like the code sample is old enough that constant was changed. At least in 8.1.2's version of Jetty, which hasn't changed in a while, it's just `MULTIPART_CONFIG_ELEMENT` - no leading underscores.

Although you may end up running into this issue:

> [@Decode "multipart/form-data" with WebDev](http://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.

---

<div class="post-metadata">

**Author:** ![djones](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@djones](https://forum.inductiveautomation.com/u/djones)\
**Post date:** [December 9, 2020, 11:40pm UTC](https://forum.inductiveautomation.com/t/webdev-image-upload/15704/7 "2020-12-09T23:40:45Z")

</div>

Thanks. That worked.
