This is done using filefield_paths module.