我用Ruby腳本掙扎使用他們的HTTP接口我試圖使用捲曲:: Easy.http_put但有一些問題與數據參數
這裏上傳一些圖片moodstocks是代碼,我迄今
curb = Curl::Easy.new
curb.http_auth_types = :digest
curb.username = MS_API
curb.password = MS_SECRET
curb.multipart_form_post = true
Dir.foreach(images_directory) do |image|
if image.include? '.jpg'
path = images_directory + image
filename = File.basename(path, File.extname(path))
puts "Upload #{path} with id #{filename}"
raw_url = 'http://api.moodstocks.com/v2/ref/' + filename
encoded_url = URI.parse URI.encode raw_url
curb.url = encoded_url
curb.http_put(Curl::PostField.file('image_file', path))
end
end
,這是錯誤,我得到
/Library/Ruby/Gems/2.0.0/gems/curb-0.8.5/lib/curl/easy.rb:57:in `add': no implicit conversion of nil into String (TypeError)
from /Library/Ruby/Gems/2.0.0/gems/curb-0.8.5/lib/curl/easy.rb:57:in `perform'
from upload_moodstocks.rb:37:in `http_put'
from upload_moodstocks.rb:37:in `block in <main>'
from upload_moodstocks.rb:22:in `foreach'
from upload_moodstocks.rb:22:in `<main>'
我認爲這個問題是我如何給參數的http_put的方法,但我試圖尋找一些考試Curl :: Easy.http_put並沒有發現任何東西。
任何人都可以給我一些關於它的文檔或者幫我解決這個問題。
預先感謝您
感謝,最後我解決了這個問題 – nucka