gpt4 book ai didi

Ruby 读取远程文件流

转载 作者:数据小太阳 更新时间:2023-10-29 07:33:57 24 4
gpt4 key购买 nike

我需要将一个远程文件保存到云存储服务器,所以我必须将这个文件读入文件流,我找到了这篇文章: Open an IO stream from a local file or url答案是:

require 'open-uri'
file_contents = open('local-file.txt') { |f| f.read }
web_contents = open('http://www.stackoverflow.com') {|f| f.read }

但是web_contents不对。然后我将此操作与自定义本地文件上传进行比较,格式为ASCII-8BIT,格式不一样。所以如何从远程文件中获取正确的流。

最佳答案

我觉得没问题:

require 'open-uri'
web_contents = open('http://www.stackoverflow.com') {|f| f.read }

out_file = File.expand_path("~/Desktop/out.html")

File.open(out_file, "w") do |f|
f.puts web_contents
end

关于Ruby 读取远程文件流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25342802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com