Revised code for uploading files -- version 2