Remove duplicate code from File and Upload classes