我在s3上编写了一个代码来上传文件,它在Ruby上运行良好。
我试图用jruby运行相同的代码,但我的代码在上传功能之前被卡住了
我遵循的步骤
安装gem: -
jruby -S gem install aws-s3
我的代码
require 'aws/s3'
local_file = ARGV[0]
bucket = ARGV[1]
AWS::S3::Base.establish_connection!(
access_key_id: 'put_access_key',
secret_access_key: 'put_secret_access_key')
base_name = File.basename(local_file)
AWS::S3::S3Object.store(
base_name,
File.open(local_file),
bucket,
access: :public_read)
puts 'Uploaded!'
url = s3_obj.url_for(
"#{local_file}",
"#{bucket}",
authenticated: false)
puts "#{url}"
像这样的文件
jruby file_name.rb upload_file_name.html bucket
答案 0 :(得分:1)
我发现使用带有jruby的aws-s3 gem有一个问题。
所以,我尝试使用“aws-sdk”gem
jruby -S gem install aws-sdk
require 'aws-sdk' file_name = ARGV[0] bucket = ARGV[1] AWS.config( access_key_id: 'PUT ACCESS KEY', secret_access_key: 'PUT SECRET KEY') s3 = AWS::S3.new base_name = File.basename(file_name) o = s3.buckets[bucket].objects[base_name].write(File.open(file_name)) puts '--------------Uploaded!-------------------' o.acl = :public_read_write url = o.public_url puts "#{url}"
运行
jruby file_name.rb upload_file_name.html path_bucket_where_to_upload