# 主题中损坏上传的链接在 2.5.0 版本中导致 500 错误

**URL:** <https://meta.discourse.org/t/links-to-broken-uploads-in-topics-lead-to-500-errors-with-2-5-0/151750>\
**Category:** Product Support\
**Created:** [2020 年5 月 17 日 12:34 UTC](https://meta.discourse.org/t/links-to-broken-uploads-in-topics-lead-to-500-errors-with-2-5-0/151750 "2020-05-17T12:34:48Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

作者： ![sukria](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sukria/32/120405_2.png) [@sukria](https://meta.discourse.org/u/sukria)\
发布日期： [2020 年5 月 18 日 07:45 UTC](https://meta.discourse.org/t/links-to-broken-uploads-in-topics-lead-to-500-errors-with-2-5-0/151750/7 "2020-05-18T07:45:40Z")

</div>

我可以确认，这并非由插件引起：我在全新安装并恢复最新备份、且未安装任何插件（除 docker\_manager 外）的环境中复现了相同的错误。

我收到的第一个堆栈跟踪如下：

> 完成 500 内部服务器错误，耗时 4169 毫秒（ActiveRecord: 0.0 毫秒 | 内存分配：72058）  
> NoMethodError（nil:NilClass 未定义方法 `path'） /var/www/discourse/lib/file_store/base_store.rb:150:in `cache\_file’

我通过以下方式进行了修复：

> def cache\_file(file, filename)  
> path = get\_cache\_path\_for(filename)  
> dir = File.dirname(path)  
> FileUtils.mkdir\_p(dir) unless Dir.exist?(dir)
> 
> ```
> if file.nil?
> return
> end
> 
> FileUtils.cp(file.path, path)
> 
> ```

但这导致了第二个错误（即我在初始帖子中提到的错误）：

> 2020-05-18 07:37:40 +0000，来自 86.246.127.170 的 GET 请求“/”已启动  
> 正在处理 CategoriesController#index，格式为 HTML  
> 完成 500 内部服务器错误，耗时 4342 毫秒（ActiveRecord: 0.0 毫秒 | 内存分配：60478）  
> NoMethodError（nil:NilClass 未定义方法 `path'） /var/www/discourse/app/models/upload.rb:193:in `fix\_dimensions!’

我通过将 local? 强制设为 true 来修复此问题：

> def local?  
> return true  
> !(url =~ /^(https?:)?///)  
> end

---

_[View the full topic](https://meta.discourse.org/t/links-to-broken-uploads-in-topics-lead-to-500-errors-with-2-5-0/151750)._
