Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Excon::Error::RequestEntityTooLarge:应为(200)<=&燃气轮机;实际(413请求实体太大):Fog google storage ruby_Ruby On Rails_Ruby_Google Cloud Storage_Fog - Fatal编程技术网

Ruby on rails Excon::Error::RequestEntityTooLarge:应为(200)<=&燃气轮机;实际(413请求实体太大):Fog google storage ruby

Ruby on rails Excon::Error::RequestEntityTooLarge:应为(200)<=&燃气轮机;实际(413请求实体太大):Fog google storage ruby,ruby-on-rails,ruby,google-cloud-storage,fog,Ruby On Rails,Ruby,Google Cloud Storage,Fog,我有一个rails应用程序5.2,ruby 2.3.4和fog google(1.3.3) 从很长一段时间上传和下载文件以来,它在开发、测试和产品环境中工作得非常好 但现在fog存储拒绝上传文件 如果我打开一个轨道c并把 config = Rails.application.config.x.settings["cloud_storage"] fogStorage = Fog::Storage.new( provider: "Google", google_storage_access_k

我有一个rails应用程序5.2,ruby 2.3.4和fog google(1.3.3)

从很长一段时间上传和下载文件以来,它在开发、测试和产品环境中工作得非常好

但现在fog存储拒绝上传文件

如果我打开一个轨道c并把

config = Rails.application.config.x.settings["cloud_storage"]

fogStorage = Fog::Storage.new(
 provider: "Google",
 google_storage_access_key_id:     config["access_key_id"],
 google_storage_secret_access_key: config["secret_access_key"]
)

storageBucket = fogStorage.directories.new key: config["bucket"]

file_name = File.join(Rails.root,"DSC00174.jpg")
file = File.open(file_name, "r")
image = storageBucket.files.new(
  key: "logo_client_image_test/AAA.jpg",
  body: file.read,
  public: true
  content_type:'image/jpeg'
)
image.save
puts image.public_url
我收到了这个消息

Excon::Error::RequestEntityTooLarge: Expected(200) <=> Actual(413 Request Entity Too Large)
excon.error.response
  :body          => "<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n  <title>Error 413 (Request Entity Too Large)!!1</title>\n  <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n  </style>\n  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n  <p><b>413.</b> <ins>That\xE2\x80\x99s an error.</ins>\n  <p>Your client issued a request that was too large.\n <script>\n  (function() { var c=function(a,d,b){a=a+\"=deleted\"+(\"; path=\"+d);null!=b&&(a+=\"; domain=\"+b);document.cookie=a+\"; expires=Thu, 01 Jan 1970 00:00:00 GMT\"};var g=function(a){var d=e,b=location.hostname;c(d,a,null);c(d,a,b);for(var f=0;;){f=b.indexOf(\".\",f+1);if(0>f)break;c(d,a,b.substring(f+1))}};var h;if(4E3<unescape(encodeURI(document.cookie)).length){for(var k=document.cookie.split(\";\"),l=[],m=0;m<k.length;m++){var n=k[m].match(/^\\s*([^=]+)/);n&&l.push(n[1])}for(var p=0;p<l.length;p++){var e=l[p];g(\"/\");for(var q=location.pathname,r=0;;){r=q.indexOf(\"/\",r+1);if(0>r)break;var t=q.substring(0,r);g(t);g(t+\"/\")}\"/\"!=q.charAt(q.length-1)&&(g(q),g(q+\"/\"))}h=!0}else h=!1;\nh&&setTimeout(function(){if(history.replaceState){var a=location.href;history.replaceState(null,\"\",\"/\");location.replace(a)}},1E3); })();\n\n</script>\n <ins>That\xE2\x80\x99s all we know.</ins>\n"
  :cookies       => [
  ]
  :headers       => {
    "Content-Length"  => "2398"
    "Content-Type"    => "text/html; charset=UTF-8"
    "Date"            => "Thu, 19 Jul 2018 10:11:50 GMT"
    "Referrer-Policy" => "no-referrer"
  }
  :host          => "locabri.storage.googleapis.com"
  :local_address => "192.168.1.44"
  :local_port    => 51136
  :path          => "/logo_client_image_test%2FAAADSC00174.jpg"
  :port          => 443
  :reason_phrase => "Request Entity Too Large"
  :remote_ip     => "216.58.206.240"
  :status        => 413
  :status_line   => "HTTP/1.0 413 Request Entity Too Large\r\n"

希望能对某人有所帮助

您能将您的解决方案发布为下面的答案吗?或者我会在几天后把你的答案贴出来。答案我自己找到了答案。在rails 5.2中,body必须是file notfile.read image=storageBucket.files.new(key:“logo\u client\u image\u test/AAA.jpg”,body:file,public:true content\u type:“image/jpeg”)是的,因此您可以在下面发布解决方案作为问题的答案,然后此线程可以标记为已解决-:)
image = storageBucket.files.new(
key: "logo_client_image_test/AAA.jpg",
body: file,
public: true
content_type:'image/jpeg'
)