Class: Uppy::S3Multipart::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/uppy/s3_multipart/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, presigned_host: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/uppy/s3_multipart/client.rb', line 8

def initialize(bucket:, presigned_host: nil)
  @bucket           = bucket
  @presigned_client = build_presigned_client(bucket.client, presigned_host) if presigned_host
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



6
7
8
# File 'lib/uppy/s3_multipart/client.rb', line 6

def bucket
  @bucket
end

Instance Method Details

#abort_multipart_upload(upload_id:, key:, **options) ⇒ Object



58
59
60
61
62
63
# File 'lib/uppy/s3_multipart/client.rb', line 58

def abort_multipart_upload(upload_id:, key:, **options)
  multipart_upload = multipart_upload(upload_id, key)
  multipart_upload.abort(**options)

  {}
end

#complete_multipart_upload(upload_id:, key:, parts:, **options) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/uppy/s3_multipart/client.rb', line 40

def complete_multipart_upload(upload_id:, key:, parts:, **options)
  multipart_upload = multipart_upload(upload_id, key)
  multipart_upload.complete(
    multipart_upload: { parts: parts },
    **options
  )

  { location: object_url(key: key) }
end

#create_multipart_upload(key:, **options) ⇒ Object



13
14
15
16
17
# File 'lib/uppy/s3_multipart/client.rb', line 13

def create_multipart_upload(key:, **options)
  multipart_upload = object(key).initiate_multipart_upload(**options)

  { upload_id: multipart_upload.id, key: multipart_upload.object_key }
end

#list_parts(upload_id:, key:, **options) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/uppy/s3_multipart/client.rb', line 19

def list_parts(upload_id:, key:, **options)
  multipart_upload = multipart_upload(upload_id, key)
  multipart_parts  = multipart_upload.parts(**options).to_a

  multipart_parts.map do |part|
    { part_number: part.part_number, size: part.size, etag: part.etag }
  end
end

#object_url(key:, public: nil, **options) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/uppy/s3_multipart/client.rb', line 50

def object_url(key:, public: nil, **options)
  if public
    object(key).public_url(**options)
  else
    presigner.presigned_url(:get_object, bucket: bucket.name, key: object(key).key, **options)
  end
end

#prepare_upload_part(upload_id:, key:, part_number:, **options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/uppy/s3_multipart/client.rb', line 28

def prepare_upload_part(upload_id:, key:, part_number:, **options)
  presigned_url = presigner.presigned_url :upload_part,
    bucket: bucket.name,
    key: object(key).key,
    upload_id: upload_id,
    part_number: part_number,
    body: "",
    **options

  { url: presigned_url }
end