Before uploading media, get the correct mime type and file name. Fixes #1081.