# Issue with upload avatar during import

**URL:** <https://meta.discourse.org/t/issue-with-upload-avatar-during-import/84227>\
**Category:** Development\
**Created:** [March 30, 2018, 1:41pm UTC](https://meta.discourse.org/t/issue-with-upload-avatar-during-import/84227 "2018-03-30T13:41:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Cara](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Cara](https://meta.discourse.org/u/Cara)\
**Post date:** [April 2, 2018, 6:18am UTC](https://meta.discourse.org/t/issue-with-upload-avatar-during-import/84227/4 "2018-04-02T06:18:26Z")

</div>

I finally achieve the upload like this:

```
create_users(results, total: total_count, offset: offset) do |user|
        { id: user['id'],
          email: user['email'],
          username: user['username'],
          name: user['name'],
          created_at: Time.zone.at(user['created_at']),
          website: user['website'],
          registration_ip_address: user['registration_ip_address'],
          location: user['location'],
          #moderator: user['group_id'] == 4,
          #admin: user['group_id'] == 1 ,
          post_create_action: proc do |newuser|
            path=File.join("/var/www/discourse/avatars", user['avatar_file'])
            if File.exists?(path)
              upload = create_upload(newuser.id, path, File.basename(path))
              if upload.nil?
                puts "Upload failed. Path #{path} Id New #{newuser.id}"
              else
                newuser.create_user_avatar
                newuser.user_avatar.update(custom_upload_id: upload.id)
                newuser.update(uploaded_avatar_id: upload.id)
              end
            end
          end
        }

```

Thanks for the help and best regards! 🙂

---

_[View the full topic](https://meta.discourse.org/t/issue-with-upload-avatar-during-import/84227)._
