Fix bug in upload_to