# Buggy code
def _on_part_start(self, name, content_type, filename=None):
    """
    Called for new parts in the multipart stream. If ``filename`` is given creates new ``file`` part (which leads
    to storage of the data as temporary file on disk), if not creates a new ``data`` part (which stores
    incoming data in memory).

    Structure of ``file`` parts:

    * ``name``: name of the part
    * ``filename``: filename associated with the part
    * ``path``: path to the temporary file storing the file's data
    * ``content_type``: content type of the part
    * ``file``: file handle for the temporary file (mode "wb", not deleted on close, will be deleted however after
      handling of the request has finished in :func:`_handle_method`)

    Structure of ``data`` parts:

    * ``name``: name of the part
    * ``content_type``: content type of the part
    * ``data``: bytes of the part (initialized to an empty string)

    :param name: name of the part
    :param content_type: content type of the part
    :param filename: filename associated with the part.
    :return: dict describing the new part
    """
    if filename is not None:
        # this is a file
        import tempfile

        handle = tempfile.NamedTemporaryFile(
            mode="wb",
            prefix=self._file_prefix,
            suffix=self._file_suffix,
            dir=self._path,
            delete=False,
        )
        return dict(
            name=tornado.escape.utf8(name),
            filename=tornado.escape.utf8(filename),
            path=tornado.escape.utf8(handle.name),
            content_type=tornado.escape.utf8(content_type),
            file=handle,
        )

    else:
        return dict(name=tornado.escape.utf8(name), content_type=content_type, data=b"")


# Traceback (AttributeError)
2016-10-04 17:22:29,805 - octoprint - ERROR - Exception on /api/files/local [POST]
Traceback (most recent call last):
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1473, in full_dispatch_request
rv = self.preprocess_request()
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1666, in preprocess_request
rv = func()
File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.2.16-py2.7.egg/octoprint/server/__init__.py", line 675, in before_request
g.locale = self._get_locale()
File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.2.16-py2.7.egg/octoprint/server/__init__.py", line 543, in _get_locale
if "l10n" in request.values:
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/utils.py", line 77, in __get__
value = self.func(obj)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/wrappers.py", line 390, in values
for d in self.args, self.form:
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/utils.py", line 77, in __get__
value = self.func(obj)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/wrappers.py", line 383, in form
self._load_form_data()
File "/home/pi/oprint/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/wrappers.py", line 165, in _load_form_data
RequestBase._load_form_data(self)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/wrappers.py", line 318, in _load_form_data
data = parser.parse_from_environ(self.environ)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/formparser.py", line 164, in parse_from_environ
return self.parse(stream, mimetype, content_length, options)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/formparser.py", line 182, in parse
input_stream = LimitedStream(stream, content_length)
File "/home/pi/oprint/local/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/wsgi.py", line 736, in __init__
self._read = stream.read
AttributeError: 'unicode' object has no attribute 'read'
2016-10-04 17:34:06,720 - octoprint.server.util.sockjs - INFO - Client connection closed: 172.20.10.3

# Fixed code
def _on_part_start(self, name, content_type, filename=None):
    """
    Called for new parts in the multipart stream. If ``filename`` is given creates new ``file`` part (which leads
    to storage of the data as temporary file on disk), if not creates a new ``data`` part (which stores
    incoming data in memory).

    Structure of ``file`` parts:

    * ``name``: name of the part
    * ``filename``: filename associated with the part
    * ``path``: path to the temporary file storing the file's data
    * ``content_type``: content type of the part
    * ``file``: file handle for the temporary file (mode "wb", not deleted on close, will be deleted however after
      handling of the request has finished in :func:`_handle_method`)

    Structure of ``data`` parts:

    * ``name``: name of the part
    * ``content_type``: content type of the part
    * ``data``: bytes of the part (initialized to an empty string)

    :param name: name of the part
    :param content_type: content type of the part
    :param filename: filename associated with the part.
    :return: dict describing the new part
    """
    if filename is not None:
        # this is a file
        import tempfile

        handle = tempfile.NamedTemporaryFile(
            mode="wb",
            prefix=self._file_prefix,
            suffix=self._file_suffix,
            dir=self._path,
            delete=False,
        )
        return dict(
            name=tornado.escape.utf8(name),
            filename=tornado.escape.utf8(filename),
            path=tornado.escape.utf8(handle.name),
            content_type=tornado.escape.utf8(content_type),
            file=handle,
        )

    else:
        return dict(
            name=tornado.escape.utf8(name),
            content_type=tornado.escape.utf8(content_type),
            data=b"",
        )