Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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 检查web文件是否存在,而不下载它?_Ruby - Fatal编程技术网

Ruby 检查web文件是否存在,而不下载它?

Ruby 检查web文件是否存在,而不下载它?,ruby,Ruby,是否有可能在不下载文件的情况下检查文件是否存在 我有一个大的(~40mb)文件,例如: 这与ruby没有严格的关系,但是如果发送者可以设置内容长度就好了 RestClient.get "http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm", headers: {"Content-Length" => 100} 尝试RestClient.head。(参见。) 有关HE

是否有可能在不下载文件的情况下检查文件是否存在

我有一个大的(~40mb)文件,例如:

这与ruby没有严格的关系,但是如果发送者可以设置内容长度就好了

RestClient.get "http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm", 
               headers: {"Content-Length" => 100}

尝试
RestClient.head
。(参见。)


有关HEAD请求,请参见第9.4节。

我们可以使用wget:

  def file_exists?(full_file_path)
      resp = `wget --spider -v #{full_file_path} && echo 1 || echo 0`
      resp.to_i.zero? ? false : true
  end

是的,还有15秒我才能给你确认