Handled nil uri in save_media()

Sometimes save_media is invoked with nil uri, in which case the script terminates. Added condition to handle this gracefully.