File: put_object.rb

package info (click to toggle)
ruby-fog-aliyun 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: ruby: 5,804; makefile: 6; sh: 3
file content (35 lines) | stat: -rw-r--r-- 968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Fog
  module Aliyun
    class Storage
      class Real
        # Put details for object
        #
        # ==== Parameters
        # * bucket_name<~String> - Name of bucket to look for
        # * object_name<~String> - Object of object to look for
        # * data<~File>
        # * options<~Hash>
        #
        def put_object(bucket_name, object_name, data, options = {})
          if data.is_a? ::File
            @oss_protocol.put_object(bucket_name, object_name, options)do |sw|
              while line = data.read(16*1024)
                sw.write(line)
              end
            end
          else
            content=StringIO.new(data.dup)
            @oss_protocol.put_object(bucket_name, object_name, options)do |sw|
              while line=content.read(16*1024)
                sw.write(line)
              end
            end
            content.close
          end
        end
      end
    end
  end
end