载波抛出“堆栈级别太深”文件上传错误

发布于 2024-11-26 16:29:54 字数 3153 浏览 0 评论 0原文

我有一个奇怪的问题,现在不知道如何进一步调试...

如果我用 html 表单上传一个文件,我得到:

SystemStackError (stack level too deep):

跟踪是:

Started POST "/global/accounts/82" for 127.0.0.1 at 2011-07-27 10:28:03 +0200
  Processing by Global::AccountsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"tAf/cGPjW+uGgdl6J7t+IZgGsNKkVDLCCWYMFdtQd7g=", "account"=>{"logo_cache"=>"", "shortcut_icon"=>#<ActionDispatch::Http::UploadedFile:0x0000010632daa0 @original_filename="18677_265409985796_708130796_4889342_5500573_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"account[shortcut_icon]\"; filename=\"18677_265409985796_708130796_4889342_5500573_n.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20110727-3683-1yazc7m>>, "shortcut_icon_cache"=>""}, "commit"=>"Einstellungen speichern", "member"=>{"cancel"=>:get}, "id"=>"82"}
  User Load (1.1ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 261 LIMIT 1
  Account Load (0.8ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`id` = 82 LIMIT 1
  SQL (2.0ms)  describe `roles_users`
  Role Load (3.8ms)  SELECT `roles`.* FROM `roles` INNER JOIN `roles_users` ON `roles`.id = `roles_users`.role_id WHERE `roles`.`name` = 'admin' AND (`roles_users`.user_id = 261 ) LIMIT 1
  Account Load (1.9ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = '***' LIMIT 1
  SQL (0.2ms)  BEGIN
  SQL (0.6ms)  SELECT 1 FROM `accounts` WHERE (LOWER(`accounts`.`subdomain`) = LOWER('***')) AND (`accounts`.id <> 82) LIMIT 1
  AREL (0.5ms)  UPDATE `accounts` SET `shortcut_icon` = 'aadf09e05f4db4124c62bfb9340aa9bd.jpg', `updated_at` = '2011-07-27 08:28:08' WHERE `accounts`.`id` = 82
  Account Load (0.5ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`id` = 82 LIMIT 1
  SQL (1.2ms)  ROLLBACK
Completed   in 2831ms

SystemStackError (stack level too deep):

分析跟踪,似乎文件已上传并写入数据库:

 AREL (0.5ms)  UPDATE `accounts` SET `shortcut_icon` = 'aadf09e05f4db4124c62bfb9340aa9bd.jpg', `updated_at` = '2011-07-27 08:28:08' WHERE `accounts`.`id` = 82

但之后它会抛出错误......

在 Rails 控制台中测试载波:

ruby-1.9.2-p180> path = "/Users/kalle/Desktop/button.png"
ruby-1.9.2-p180> u = Account.last
ruby-1.9.2-p180> u.logo = File.open(path)
 => #<File:/Users/kalle/Desktop/button.png> 
ruby-1.9.2-p180> u.save!
 => true 

工作正常!

好吧,我有一个文件上传@另一个模型,所以载波安装工作正常(类似的上传器)。

在没有提交文件的情况下测试 html 表单,效果很好!

所以:

  • 表单在没有文件字段的情况下工作
  • Carrierwave 文件上传在控制台
  • 不同的模型中工作,类似的 Carrierwave uploader/config =>作品!

我如何进一步调试?

感谢您的帮助!

Rails 3.0.7/ruby-1.9.2-p180/carrierwave (0.5.3)

编辑: 似乎它只发生在更新操作上。

控制器:

def update
  if current_account.update_attributes(params[:account])
    flash[:notice] = 'Successfully updated account.'
    redirect_to global_settings_path
  else
    render :action => 'edit'
  end
end

i have a weired problem and don't now how to debug further...

if i upload an file with my html form i get:

SystemStackError (stack level too deep):

the trace is:

Started POST "/global/accounts/82" for 127.0.0.1 at 2011-07-27 10:28:03 +0200
  Processing by Global::AccountsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"tAf/cGPjW+uGgdl6J7t+IZgGsNKkVDLCCWYMFdtQd7g=", "account"=>{"logo_cache"=>"", "shortcut_icon"=>#<ActionDispatch::Http::UploadedFile:0x0000010632daa0 @original_filename="18677_265409985796_708130796_4889342_5500573_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"account[shortcut_icon]\"; filename=\"18677_265409985796_708130796_4889342_5500573_n.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20110727-3683-1yazc7m>>, "shortcut_icon_cache"=>""}, "commit"=>"Einstellungen speichern", "member"=>{"cancel"=>:get}, "id"=>"82"}
  User Load (1.1ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 261 LIMIT 1
  Account Load (0.8ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`id` = 82 LIMIT 1
  SQL (2.0ms)  describe `roles_users`
  Role Load (3.8ms)  SELECT `roles`.* FROM `roles` INNER JOIN `roles_users` ON `roles`.id = `roles_users`.role_id WHERE `roles`.`name` = 'admin' AND (`roles_users`.user_id = 261 ) LIMIT 1
  Account Load (1.9ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = '***' LIMIT 1
  SQL (0.2ms)  BEGIN
  SQL (0.6ms)  SELECT 1 FROM `accounts` WHERE (LOWER(`accounts`.`subdomain`) = LOWER('***')) AND (`accounts`.id <> 82) LIMIT 1
  AREL (0.5ms)  UPDATE `accounts` SET `shortcut_icon` = 'aadf09e05f4db4124c62bfb9340aa9bd.jpg', `updated_at` = '2011-07-27 08:28:08' WHERE `accounts`.`id` = 82
  Account Load (0.5ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`id` = 82 LIMIT 1
  SQL (1.2ms)  ROLLBACK
Completed   in 2831ms

SystemStackError (stack level too deep):

analysing the trace, it seems that the file is uploaded and written to the DB:

 AREL (0.5ms)  UPDATE `accounts` SET `shortcut_icon` = 'aadf09e05f4db4124c62bfb9340aa9bd.jpg', `updated_at` = '2011-07-27 08:28:08' WHERE `accounts`.`id` = 82

but after that it throws the error....

testing carrierwave in the rails console:

ruby-1.9.2-p180> path = "/Users/kalle/Desktop/button.png"
ruby-1.9.2-p180> u = Account.last
ruby-1.9.2-p180> u.logo = File.open(path)
 => #<File:/Users/kalle/Desktop/button.png> 
ruby-1.9.2-p180> u.save!
 => true 

works fine!

well, i have a file upload @ another model, so the carrierwave installation works fine (similar uploader).

testing the html form without the file filed, it works fine!

so:

  • Form works without file field
  • carrierwave file upload works in the console
  • different model, similar carrierwave uploader/config => works!

how can i debug further ?

thanks for any help!

Rails 3.0.7/ruby-1.9.2-p180/carrierwave (0.5.3)

EDIT:
seems that it happens only on the update action.

controller:

def update
  if current_account.update_attributes(params[:account])
    flash[:notice] = 'Successfully updated account.'
    redirect_to global_settings_path
  else
    render :action => 'edit'
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独闯女儿国 2024-12-03 16:29:54

我有类似的问题。
当我调用 photo.url 时,它抛出了“堆栈级别深度错误”。

我的 PhotoUploader 中似乎有以下代码:

  def url
    filename = self.to_s
    content_type = File.mime_type?(filename)    
    ext = {
      'image/png'  => :png,
      'image/jpg'  => :jpg,
      'image/jpeg' => :jpg,
      'image/gif'  => :gif

    }[content_type]
    ext ||= :jpg

    { :id => model.id, :version => version_name, :format => ext }    
  end

该代码似乎在 Carrierwave 0.5.8 中工作正常。
我更新到0.6.2,但失败了。

问题是我正在调用 self.to_s。正如我在载波代码中发现的:
to_s 是这样实现的:

  def to_s
    url || ''
  end

通过将 self.to_s 更改为 self.file 问题得到解决

  def url
    filename = self.file
    # ... rest of the code ..
  end 

I had a similar problem.
When I called photo.url it throwed a "stack level to deep error".

It seemed I had the following code in my PhotoUploader:

  def url
    filename = self.to_s
    content_type = File.mime_type?(filename)    
    ext = {
      'image/png'  => :png,
      'image/jpg'  => :jpg,
      'image/jpeg' => :jpg,
      'image/gif'  => :gif

    }[content_type]
    ext ||= :jpg

    { :id => model.id, :version => version_name, :format => ext }    
  end

This code seemed to work fine in carrierwave 0.5.8.
I updated to 0.6.2 and since it failed.

The problem is I'm calling self.to_s. As I found out in the carrierwave code:
to_s is implemented like this:

  def to_s
    url || ''
  end

By changing self.to_s to self.file the problem was solved

  def url
    filename = self.file
    # ... rest of the code ..
  end 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文