Revised code for uploading files