lib/tori/backend/s3.rb in tori-0.5.0 vs lib/tori/backend/s3.rb in tori-0.6.0
- old
+ new
@@ -128,9 +128,29 @@
def url_for(filename, method)
signer = Aws::S3::Presigner.new(client: client)
signer.presigned_url(method, bucket: @bucket, key: filename)
end
+ def open(filename)
+ ext = ::File.extname(filename)
+ body = body(filename)
+
+ if block_given?
+ Tempfile.create([filename, ext]) do |f|
+ f.write body
+ f.fsync
+ f.rewind
+ yield f
+ end
+ else
+ f = Tempfile.open([filename, ext])
+ f.write body
+ f.fsync
+ f.rewind
+ f
+ end
+ end
+
def get_object(opts={})
client.get_object bucket: @bucket, **opts
end
def head_object(opts={})