如何解决Faraday::Adapter::NetHttpPersistent 缺少依赖项:无法加载此类文件 -- net/http/persistent
具有持久 HTTP 调用的最新版 azure-storage-common 2.0.2
失败并出现以下错误:
missing dependency for Faraday::Adapter::NetHttpPersistent: cannot load such file -- net/http/persistent
呼叫是 create_block_blob
。
已指定适当的依赖项:
gem 'faraday_middleware','1.0.0',{require: false}
gem 'net-http-persistent','4.0.0',{require: false}
gem 'azure-storage-common','2.0.2',{require: false}
gem 'azure-storage-blob','2.0.1',{require: false}
require 'azure/storage/blob'
是的,我可以看到 net-http-persistent
被捆绑。
我尝试将:require 'net/http/persistent'
放在这里,但没有帮助。同样的错误。
有什么指点吗?
编辑:
抱歉我没说清楚。我正在使用捆绑程序。并且 net-http-persistent
已捆绑。
我将 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
存储名称和密钥是从这个地方获取的:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。