From d0a1922ad9b2fb8d3581e44724ce679d88821abe Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 28 Mar 2019 15:58:42 +0800 Subject: [PATCH] FIX: `Upload.migrate_to_new_scheme` undefined error when external image fails to download. --- app/models/upload.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index fd3f3c86a2e..9de4e28d883 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -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)