Ruby on rails Faraday::Adapter::NetHttpPersistent缺少依赖项:无法加载这样的文件--net/http/persistent
具有持久HTTP调用的最新版本azure storage common 2.0.2失败,出现以下错误:Ruby on rails Faraday::Adapter::NetHttpPersistent缺少依赖项:无法加载这样的文件--net/http/persistent,ruby-on-rails,ruby,azure-storage-blobs,Ruby On Rails,Ruby,Azure Storage Blobs,具有持久HTTP调用的最新版本azure storage common 2.0.2失败,出现以下错误: missing dependency for Faraday::Adapter::NetHttpPersistent: cannot load such file -- net/http/persistent 调用是create\u block\u blob 已指定相应的依赖项: gem'faraday_中间件','1.0.0',{require:false} gem'nethttppers
missing dependency for Faraday::Adapter::NetHttpPersistent: cannot load such file -- net/http/persistent
调用是create\u block\u blob
已指定相应的依赖项:
gem'faraday_中间件','1.0.0',{require:false}
gem'nethttppersistent','4.0.0',{require:false}
gem'azure存储公用','2.0.2',{require:false}
gem'azure存储blob','2.0.1',{require:false}
需要“azure/storage/blob”
是的,我可以看到nethttppersistent
被捆绑
我试着把:require'net/http/persistent'
放在这里,但没有用。同样的错误
有什么建议吗
编辑:
对不起,我没说清楚。我正在使用Bundler。而且,nethttp持久性
已经捆绑
我将
require'net/http/persistent'
放在每个函数调用之前,它仍然会返回此错误,即使require
语句返回true
表示模块已加载。我首先通过以下方法安装azure blob存储包:
gem install azure-storage-blob
然后,我使用下面的代码,它似乎工作得很好:
require "openssl"
require "securerandom"
require "rbconfig"
# Require the azure storage blob rubygem
require "azure/storage/blob"
$stdout.sync = true
# This sample application creates a container in an Azure Blob Storage account,
# uploads data to the container, lists the blobs in the container, and downloads a blob to a local file.
def run_sample
is_windows = (RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/)
# Create a BlobService object
blob_client = Azure::Storage::Blob::BlobService
begin
# Create a BlobService object
account_name = "yourstorageaccountname"
account_key = "xxxxxx=="
blob_client = Azure::Storage::Blob::BlobService.create(
storage_account_name: account_name,
storage_access_key: account_key
)
# Create a container
container_name = "quickstartblobs" + SecureRandom.uuid
puts "\nCreating a container: " + container_name
container = blob_client.create_container(container_name)
# Set the permission so the blobs are public
blob_client.set_container_acl(container_name, "container")
# Create a new block blob containing 'Hello, World!'
blob_name = "QuickStart_" + SecureRandom.uuid + ".txt"
blob_data = "Hello, World!"
puts "\nCreating blob: " + blob_name
blob_client.create_block_blob(container.name, blob_name, blob_data)
# List the blobs in the container
puts "\nList blobs in the container following continuation token"
nextMarker = nil
loop do
blobs = blob_client.list_blobs(container_name, { marker: nextMarker })
blobs.each do |blob|
puts "\tBlob name: #{blob.name}"
end
nextMarker = blobs.continuation_token
break unless nextMarker && !nextMarker.empty?
end
# Download the blob
# Set the path to the local folder for downloading
if(is_windows)
local_path = File.expand_path("~/Documents")
else
local_path = File.expand_path("~/")
end
# Create the full path to the downloaded file
full_path_to_file = File.join(local_path, blob_name)
puts "\nDownloading blob to " + full_path_to_file
blob, content = blob_client.get_blob(container_name, blob_name)
File.open(full_path_to_file,"wb") {|f| f.write(content)}
puts "\nPaused, press the Enter key to delete resources created by the sample and exit the application "
readline()
rescue Exception => e
puts e.message
ensure
# Clean up resources, including the container and the downloaded file
blob_client.delete_container(container_name)
File.delete(full_path_to_file)
end
end
# Main method
run_sample
存储名称和密钥来自以下位置:
我使用的是Bundler,所以它应该被捆绑。对不起,我没说清楚。最后,我在每个函数调用之前都放了一个
require'net/http/persistnt'
语句,但它仍然不起作用。require
语句返回true
表示它已加载,但仍然返回此错误。