Class: Canistor::Storage::Upload
- Inherits:
-
Object
- Object
- Canistor::Storage::Upload
- Defined in:
- lib/canistor/storage/upload.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#region ⇒ Object
Returns the value of attribute region.
Instance Method Summary collapse
- #get(context) ⇒ Object
-
#initialize(**attributes) ⇒ Upload
constructor
A new instance of Upload.
- #post(context, subject) ⇒ Object
- #put(context, subject) ⇒ Object
- #write(headers) ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ Upload
Returns a new instance of Upload.
14 15 16 17 18 19 20 21 |
# File 'lib/canistor/storage/upload.rb', line 14 def initialize(**attributes) @id = SecureRandom.hex(64) @parts = {} @headers = {} attributes.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
8 9 10 |
# File 'lib/canistor/storage/upload.rb', line 8 def bucket @bucket end |
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/canistor/storage/upload.rb', line 12 def headers @headers end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/canistor/storage/upload.rb', line 6 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/canistor/storage/upload.rb', line 9 def key @key end |
#parts ⇒ Object
Returns the value of attribute parts.
10 11 12 |
# File 'lib/canistor/storage/upload.rb', line 10 def parts @parts end |
#region ⇒ Object
Returns the value of attribute region.
7 8 9 |
# File 'lib/canistor/storage/upload.rb', line 7 def region @region end |
Instance Method Details
#get(context) ⇒ Object
27 28 29 |
# File 'lib/canistor/storage/upload.rb', line 27 def get(context) list_parts(context) end |
#post(context, subject) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/canistor/storage/upload.rb', line 50 def post(context, subject) catch(:rendered_error) do object = Canistor::Storage::Object.new( region: region, bucket: bucket, key: key ) object.write(headers, String.new) each_part_in_body(context) do |part| object.data << part.data end show_complete_upload(context, object) object end end |
#put(context, subject) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/canistor/storage/upload.rb', line 31 def put(context, subject) params = CGI::parse(context.http_request.endpoint.query.to_s) if params.has_key?('uploads') write(context.http_request.headers) show_initiate_upload(context) elsif params.has_key?('partNumber') part_number = Integer(params['partNumber'][0]) part = find_or_build_part(subject, context, part_number) parts[part_number] = part part.put(context, subject) else raise( RuntimeError, "Implementation should never attempt to PUT an upload when there " \ "is no uploads or partNumber parameter present in the request." ) end end |
#write(headers) ⇒ Object
23 24 25 |
# File 'lib/canistor/storage/upload.rb', line 23 def write(headers) self.headers = headers end |