Module: Aliyun::Oss::Api::BucketMultiparts

Included in:
Client
Defined in:
lib/aliyun/oss/api/bucket_multiparts.rb

Instance Method Summary collapse

Instance Method Details

#bucket_abort_multipart(upload_id, key) ⇒ Response

Note:

After abort the Multipart Upload, the Uploaded data will be deleted

Note:

When abort a Multipart Upload event, if there are still part upload belonging to this event, then theree parts will not be removed. So if there is a concurrent access, in order to release the space on the OSS completely, you need to call #bucket_abort_multipart a few times.

Abort a Multipart Upload event

Parameters:

  • key (String)

    the object name

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

Returns:

  • (Response)

Raises:

See Also:



121
122
123
124
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 121

def bucket_abort_multipart(upload_id, key)
  query = { 'uploadId' => upload_id }
  http.delete("/#{key}", query: query, bucket: bucket, key: key)
end

#bucket_complete_multipart(upload_id, key, parts = []) ⇒ Response

Complete a Multipart Upload event.

Parameters:

  • key (String)

    object name

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • parts (Array<Aliyun::Oss::Multipart:Part>) (defaults to: [])

    parts

Returns:

  • (Response)

Raises:

See Also:



97
98
99
100
101
102
103
104
105
106
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 97

def bucket_complete_multipart(upload_id, key, parts = [])
  fail MultipartPartsEmptyError if parts.nil? || parts.empty?
  fail MultipartUploadIdEmptyError if upload_id.nil?

  query = { 'uploadId' => upload_id }

  body = XmlGenerator.generate_complete_multipart_xml(parts)

  http.post("/#{key}", query: query, body: body, bucket: bucket, key: key)
end

#bucket_init_multipart(key, headers = {}) ⇒ Response

Initialize a Multipart Upload event, before using Multipart Upload mode to transmit data, we has to call the interface to notify the OSS initialize a Multipart Upload events.

Parameters:

  • key (String)

    object name

  • headers (Hash) (defaults to: {})

    headers

Options Hash (headers):

Returns:

  • (Response)

See Also:



19
20
21
22
23
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 19

def bucket_init_multipart(key, headers = {})
  Utils.stringify_keys!(headers)
  query = { 'uploads' => true }
  http.post("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_list_multiparts(options = {}) ⇒ Response

List existing opened Multipart Upload event.

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :prefix (String)

    Filter objects with prefix

  • :delimiter (String)

    Used to group objects with delimiter

  • :max-uploads (Integer) — default: 1000

    Limit number of Multipart Upload events, the maxinum should <= 1000

  • :encoding-type (String)

    Encoding type used for unsupported character

  • :key-marker (String)

    with upload-id-marker used to specify the result range.

  • :upload-id-marker (String)

    with key-marker used to specify the result range.

Returns:

  • (Response)

See Also:



139
140
141
142
143
144
145
146
147
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 139

def bucket_list_multiparts(options = {})
  Utils.stringify_keys!(options)
  accepted_keys = ['prefix', 'key-marker', 'upload-id-marker', 'max-uploads', 'delimiter', 'encoding-type']

  query = Utils.hash_slice(options, *accepted_keys)
          .merge('uploads' => true)

  http.get('/', query: query, bucket: bucket)
end

#bucket_list_parts(upload_id, key, options = {}) ⇒ Response

List uploaded parts for Multipart Upload event

Parameters:

  • key (String)

    the object name

  • upload_id (Integer)

    the upload ID return by #bucket_init_multipart

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :max-parts (Integer) — default: 1000

    Limit number of parts, the maxinum should <= 1000

  • :part-number-marker (Integer)

    Specify the start part, return parts which number large than the specified value

  • :encoding-type (String)

    Encoding type used for unsupported character in xml 1.0

Returns:

  • (Response)

See Also:



161
162
163
164
165
166
167
168
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 161

def bucket_list_parts(upload_id, key, options = {})
  Utils.stringify_keys!(options)
  accepted_keys = ['max-parts', 'part-number-marker', 'encoding-type']

  query = Utils.hash_slice(options, *accepted_keys).merge('uploadId' => upload_id)

  http.get("/#{key}", query: query, bucket: bucket, key: key)
end

#bucket_multipart_copy_upload(upload_id, key, number, options = {}) ⇒ Response

Upload a Part from an existing Object Copy data.

Parameters:

  • key (String)

    object name

  • number (Integer)

    the part number, Range in 1~10000.

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :source_bucket (String)

    the source bucket name

  • :source_key (String)

    the source object name

  • :range (String)

    the Range bytes, not set means the whole object, eg: bytes=100-6291756

  • :x-oss-copy-source-if-match (String)

    If the specified ETag match the source object ETag, normal transfer and return 200; Otherwise return 412(precondition)

  • :x-oss-copy-source-if-none-match (String)

    If the specified ETag not match the source object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)

  • :x-oss-copy-source-if-unmodified-since (String)

    If the specified time is equal to or later than the source object last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)

  • :x-oss-copy-source-if-modified-since (String)

    If the specified time is earlier than the source object last modification time, normal transfer ans return 200; Otherwise returns 304(not modified)

Returns:

  • (Response)

Raises:

See Also:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 69

def bucket_multipart_copy_upload(upload_id, key, number, options = {})
  Utils.stringify_keys!(options)
  source_bucket = options.delete('source_bucket').to_s
  source_key = options.delete('source_key').to_s
  range = options.delete('range')

  fail MultipartSourceBucketEmptyError if source_bucket.empty?
  fail MultipartSourceKeyEmptyError if source_key.empty?

  query = { 'partNumber' => number, 'uploadId' => upload_id }
  headers = copy_upload_headers(source_bucket, source_key, range, options)

  http.put("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_multipart_upload(upload_id, key, number, file) ⇒ Response

Upload object in part.

Parameters:

  • key (String)

    object name

  • number (Integer)

    the part number, Range in 1~10000.

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • file (File, bin data)

    the upload data

Returns:

  • (Response)

Raises:

  • (RequestError)
  • (MultipartPartNumberEmptyError)
  • (MultipartUploadIdEmptyError)

See Also:



39
40
41
42
43
44
45
46
# File 'lib/aliyun/oss/api/bucket_multiparts.rb', line 39

def bucket_multipart_upload(upload_id, key, number, file)
  fail MultipartPartNumberEmptyError if number.nil?
  fail MultipartUploadIdEmptyError if upload_id.nil? || upload_id.empty?

  query = { 'partNumber' => number.to_s, 'uploadId' => upload_id }

  http.put("/#{key}", query: query, body: Utils.to_data(file), bucket: bucket, key: key)
end