refactor mime handling and upload processing