changed to use a map for files: gratuitous but fine
changed to retain mime types of incoming files