Adding changes from RWAP's fork (up to and including commit 5c1775dc7ee2cff0690f0bd1cb4841a00879703f) to add support for media uploads.