From bba3f7c0aceb6109661362a6aa834c672b4f9882 Mon Sep 17 00:00:00 2001 From: Wilhansen Li Date: Tue, 26 Aug 2014 23:52:07 +0800 Subject: [PATCH] Fix SSO avatar downloading issues. * Follow redirects when downloading SSO avatars. * Add proper image ext. to downloaded SSO avatars. --- app/models/discourse_single_sign_on.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/discourse_single_sign_on.rb b/app/models/discourse_single_sign_on.rb index 6e192717f46..0476c384f5d 100644 --- a/app/models/discourse_single_sign_on.rb +++ b/app/models/discourse_single_sign_on.rb @@ -126,10 +126,12 @@ class DiscourseSingleSignOn < SingleSignOn avatar_force_update.to_i != 0 || sso_record.external_avatar_url != avatar_url) begin - tempfile = FileHelper.download(avatar_url, 1.megabyte, "sso-avatar") + tempfile = FileHelper.download(avatar_url, 1.megabyte, "sso-avatar", true) - upload = Upload.create_for(user.id, tempfile, "external-avatar", File.size(tempfile.path), { origin: avatar_url }) + ext = FastImage.type(tempfile).to_s + tempfile.rewind + upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, File.size(tempfile.path), { origin: avatar_url }) user.uploaded_avatar_id = upload.id if !user.user_avatar.contains_upload?(upload.id)