827f977a37
Added the ability to update the contact's avatar via API and Dashboard. - Contact create and update APIs can now accept avatar attachment parameters [form data]. - Contact create and update endpoints can now accept the avatar_url parameter.[json] - API endpoint to remove a contact avatar. - Updated Contact create/edit UI components with avatar support Fixes: #3428
15 lines
521 B
Ruby
15 lines
521 B
Ruby
class ContactAvatarJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(contact, avatar_url)
|
|
avatar_file = Down.download(
|
|
avatar_url,
|
|
max_size: 15 * 1024 * 1024
|
|
)
|
|
contact.avatar.attach(io: avatar_file, filename: avatar_file.original_filename, content_type: avatar_file.content_type)
|
|
rescue Down::NotFound
|
|
contact.avatar.attachment.destroy! if contact.avatar.attached?
|
|
rescue Down::Error => e
|
|
Rails.logger.error "Exception: invalid avatar url #{avatar_url} : #{e.message}"
|
|
end
|
|
end
|