FIX: `Upload.migrate_to_new_scheme` undefined error when external image fails to download.

This commit is contained in:
Guo Xiang Tan 2019-03-28 15:58:42 +08:00
parent b5e32cfe2a
commit d0a1922ad9
1 changed files with 15 additions and 6 deletions

View File

@ -239,12 +239,21 @@ class Upload < ActiveRecord::Base
# download if external
if external
url = SiteSetting.scheme + ":" + previous_url
file = FileHelper.download(
url,
max_file_size: max_file_size_kb,
tmp_file_name: "discourse",
follow_redirect: true
) rescue nil
begin
retries ||= 0
file = FileHelper.download(
url,
max_file_size: max_file_size_kb,
tmp_file_name: "discourse",
follow_redirect: true
)
rescue OpenURI::HTTPError
retry if (retires += 1) < 1
next
end
path = file.path
else
path = local_store.path_for(upload)