# 即使设置了 DISCOURSE\_S3\_CDN\_URL，来自 S3 的下载仍然会出现

**URL:** <https://meta.discourse.org/t/downloads-coming-from-s3-even-with-discourse-s3-cdn-url-set/177000>\
**Category:** Product Support\
**Created:** [2021 年1 月 23 日 01:13 UTC](https://meta.discourse.org/t/downloads-coming-from-s3-even-with-discourse-s3-cdn-url-set/177000 "2021-01-23T01:13:14Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

作者： ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
发布日期： [2025 年4 月 23 日 14:38 UTC](https://meta.discourse.org/t/downloads-coming-from-s3-even-with-discourse-s3-cdn-url-set/177000/5 "2025-04-23T14:38:26Z")

</div>

> [@Bathinda](#):
>
> 谢谢。  
> 我已经把它交给我一个本地朋友了。他正在处理。

抱歉。我指的是另一个问题。

我敢肯定，您的问题要复杂得多。

> [@Bathinda](#):
>
> 他已将 s3 存储迁移到本地服务器。

这确实很复杂。

我认为该帖子中丢失的图片是因为 Upload 记录不存在，所以您需要做些什么来恢复该图片。我可能错了。

如果我没错，以下是我之前解决类似问题的方法。我在此脚本之外不提供任何免费支持。

```plaintext
def process_uploads
  begin
    # 读取文件名列表
    filenames = File.readlines('/shared/uploads/allfiles.txt').map(&:strip)
    count = 0

    filenames.each do |filename|
      # 在文件名开头添加 /shared
      filename.gsub!(/\.\//,"")
      full_path = File.join('/shared/uploads/default/original/', filename)

      begin
        # 检查路径是否存在且为常规文件（非目录）
        count += 1
        
        if File.exist?(full_path) && File.file?(full_path)
          # 打开文件
          File.open(full_path, 'r') do |tempfile|
            # 使用指定参数创建上传
            u = UploadCreator.new(tempfile, 'imported', {}).create_for(-1)
            puts "#{count} -- #{u.id}: #{u.url}"
          end
        else
          puts "警告：路径未找到或不是常规文件：#{full_path}"
        end
      rescue => e
        puts "处理文件 #{full_path} 时出错：#{e.message}"
        # 即使当前文件失败，也继续处理下一个文件
        next
      end
    end
  rescue Errno::ENOENT
    puts "错误：找不到 files.txt"
  rescue => e
    puts "读取 files.txt 时出错：#{e.message}"
  end
end

# 执行处理
process_uploads;

```

---

_[View the full topic](https://meta.discourse.org/t/downloads-coming-from-s3-even-with-discourse-s3-cdn-url-set/177000)._
