fix upload logic