Class: Apertur::Resources::Upload
- Inherits:
-
Object
- Object
- Apertur::Resources::Upload
- Defined in:
- lib/apertur/resources/upload.rb
Overview
Upload images to a session.
Supports both plaintext multipart uploads and client-side encrypted uploads using AES-256-GCM with RSA-OAEP key wrapping.
Instance Method Summary collapse
-
#image(uuid, file, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) ⇒ Hash
Upload an image to a session via multipart/form-data.
-
#image_encrypted(uuid, file, public_key, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) ⇒ Hash
Upload an encrypted image to a session.
-
#initialize(http) ⇒ Upload
constructor
A new instance of Upload.
Constructor Details
#initialize(http) ⇒ Upload
Returns a new instance of Upload.
11 12 13 |
# File 'lib/apertur/resources/upload.rb', line 11 def initialize(http) @http = http end |
Instance Method Details
#image(uuid, file, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) ⇒ Hash
Upload an image to a session via multipart/form-data.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/apertur/resources/upload.rb', line 25 def image(uuid, file, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) file_data = read_file(file) fields = {} fields["source"] = source if source headers = {} headers["x-session-password"] = password if password @http.request_multipart( "/api/v1/upload/#{uuid}/images", file_data, filename: filename, mime_type: mime_type, fields: fields, headers: headers ) end |
#image_encrypted(uuid, file, public_key, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) ⇒ Hash
Upload an encrypted image to a session.
The image is encrypted client-side using AES-256-GCM, with the AES key wrapped by the server’s RSA public key. The encrypted payload is sent as JSON with the X-Aptr-Encrypted: default header.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/apertur/resources/upload.rb', line 58 def image_encrypted(uuid, file, public_key, filename: "image.jpg", mime_type: "image/jpeg", source: nil, password: nil) file_data = read_file(file) encrypted = Apertur::Crypto.encrypt_image(file_data, public_key) payload = encrypted.merge( "filename" => filename, "mimeType" => mime_type, "source" => source || "sdk" ) headers = { "X-Aptr-Encrypted" => "default" } headers["x-session-password"] = password if password @http.request(:post, "/api/v1/upload/#{uuid}/images", body: payload, headers: headers) end |