2

我编写了一个代码来将我的文件上传到 S3,它可以与RUBY一起正常工作,但是如果我尝试使用JRUBY上传相同的文件,则会出现错误

-> "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

注意:- 上传特定文件时出现错误。

4

1 回答 1

0

您可以使用以下语法处理此问题

begin
  do_something
rescue AWS::Errors::ClientError
  # rescues all 400 level errors
end
于 2013-07-18T07:06:52.917 回答