我编写了一个代码将我的文件上传到S3,它可以正常使用 RUBY ,但如果我尝试使用 JRUBY 上传相同的文件,则会出错< / p>
-> "HTTP/1.1 400 Bad Request\r\n"
-> "x-amz-request-id: -------------\r\n"
-> "x-amz-id-2: some_id\r\n"
-> "Content-Type: application/xml\r\n"
-> "Transfer-Encoding: chunked\r\n"
-> "Date: Thu, 18 Jul 2013 05:50:24 GMT\r\n"
-> "Connection: close\r\n"
-> "Server: AmazonS3\r\n"
-> "\r\n"
-> "15c\r\n"
这是我的代码
# endcoding: UTF-8
require 'aws-sdk'
module Upload
def self.ufile(name)
AWS.config(
access_key_id: 'ACCESS_KEY',
secret_access_key: 'SECRET_KEY')
s3 = AWS::S3.new(logger: Logger.new($stderr), http_wire_trace: true)
bucket = 'bucket_name'
base_name = File.basename(name)
AWS.config.http_handler.pool.empty!
obj = s3.buckets[bucket].objects[base_name].write(File.open(name), content_length: File.size(name))
obj.acl = :public_read_write
obj.public_url
end
end
注意: - 上传特定文件时收到错误。
答案 0 :(得分:0)
您可以使用以下语法处理此问题
begin
do_something
rescue AWS::Errors::ClientError
# rescues all 400 level errors
end