lib/attached/storage/aws.rb in attached-0.3.9 vs lib/attached/storage/aws.rb in attached-0.4.0

- old
+ new

@@ -67,9 +67,35 @@ file.close end + # Retrieve a file from a given path. + # + # Parameters: + # + # * path - The path to retrieve. + + def retrieve(path) + directory = connection.directories.get(self.bucket) + directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket)) + + file = directory.files.get(path) + + body = file.body + + extname = File.extname(path) + basename = File.basename(path, extname) + + file = Tempfile.new([basename, extname]) + file.binmode + file.write(body) + file.rewind + + file + end + + # Destroy a file at a given path. # # Parameters: # # * path - The path to destroy. \ No newline at end of file