Class: StableDiffusionRuby::Storage::S3
- Inherits:
-
Object
- Object
- StableDiffusionRuby::Storage::S3
- Defined in:
- lib/stable_diffusion_ruby/storage/s3.rb
Class Method Summary collapse
-
.create_upload_target(filename) ⇒ Object
Create a pre-signed PUT URL for remote workers to upload results, returns [key, PUT URL].
-
.delete(*keys) ⇒ Object
Clean up temp S3 objects (best-effort, never raises).
-
.download(key, local_path) ⇒ Object
Download an S3 object to a local path.
-
.reset! ⇒ Object
Reset cached client (useful for reconfiguration).
-
.upload(local_path) ⇒ Object
Upload a local file to S3, returns [key, pre-signed GET URL].
Class Method Details
.create_upload_target(filename) ⇒ Object
Create a pre-signed PUT URL for remote workers to upload results, returns [key, PUT URL]
20 21 22 23 |
# File 'lib/stable_diffusion_ruby/storage/s3.rb', line 20 def create_upload_target(filename) key = temp_key(filename) [key, presigned_put_url(key)] end |
.delete(*keys) ⇒ Object
Clean up temp S3 objects (best-effort, never raises)
32 33 34 35 36 37 38 |
# File 'lib/stable_diffusion_ruby/storage/s3.rb', line 32 def delete(*keys) keys.flatten.compact.each do |key| client.delete_object(bucket: bucket, key: key) rescue Aws::S3::Errors::ServiceError => error StableDiffusionRuby.logger.warn("[StableDiffusionRuby::Storage::S3] Failed to delete #{key}: #{error.}") end end |
.download(key, local_path) ⇒ Object
Download an S3 object to a local path
26 27 28 29 |
# File 'lib/stable_diffusion_ruby/storage/s3.rb', line 26 def download(key, local_path) client.get_object(bucket: bucket, key: key, response_target: local_path) local_path end |
.reset! ⇒ Object
Reset cached client (useful for reconfiguration)
41 42 43 44 |
# File 'lib/stable_diffusion_ruby/storage/s3.rb', line 41 def reset! @client = nil @presigner = nil end |
.upload(local_path) ⇒ Object
Upload a local file to S3, returns [key, pre-signed GET URL]
11 12 13 14 15 16 17 |
# File 'lib/stable_diffusion_ruby/storage/s3.rb', line 11 def upload(local_path) key = temp_key(File.basename(local_path)) File.open(local_path, "rb") do |file| client.put_object(bucket: bucket, key: key, body: file) end [key, presigned_get_url(key)] end |