fix image upload logic