我正在尝试使用paperclip调用我的自定义api uploades文件,使用https://github.com/jwagener/httmultiparty在本地工作正常,但是当我尝试为heroku部署应用程序调用api和上传文件时,会发生以下错误。
NoMethodError: undefined method `bytesize' for #<Array:0x00000006e71980>
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1735:in `send_request_with_body'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1724:in `exec'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1189:in `transport_request'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1177:in `request'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:627:in `start'
from /home/umair/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/httparty-0.8.3/lib/httparty/request.rb:76:in `perform'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/httparty-0.8.3/lib/httparty/request.rb:208:in `handle_response'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/httparty-0.8.3/lib/httparty/request.rb:90:in `perform'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/httparty-0.8.3/lib/httparty.rb:400:in `perform_request'
from /home/umair/Projects/core/lib/httmultiparty.rb:81:in `post'
from (irb):5
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /home/umair/.rvm/gems/ruby-1.9.2-p320@gm/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
我在ruby控制台上运行它来测试文件上传API。
HttpClient.post('/storage.xml',:basic_auth=> {:username=>'badde88248834bec759d94563f102d52e19702fa',:password=>'b890b48e2769192372bf531fc46827cd86bea23f'} ,:query => {:auth_token=> '1045aa26cda23f5f3aec737a45e7ba0017c1a7cf',:user_file => File.new( '/home/umair/Login.png')})
答案 0 :(得分:0)
我遇到了同样的问题但无法找到解决方案。现在我这样做,它只需要multipart-post
宝石。
class Client
require 'net/http/post/multipart'
def self.perform inputurl, file
url = URI.parse(inputurl)
File.open(file) do |transfile|
Net::HTTP.start(url.host, url.port) do |http|
req = Net::HTTP::Post::Multipart.new(
url.path,
file1: UploadIO.new(transfile, "multipart/formdata", File.basename(file)),
)
response = http.request(req)
end
end
end
end