Sha256: 90ed73eebfe4a2a92b571435f1741e204ab83ea01e9d06b77863b3e916b65f81

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

require 's3'

class S3Service
	def initialize(key_id, key_secret, bucket, options = {})
		@options = options
		@logger = (options[:logger] or Logger.new('/dev/null'))

		@s3 = S3::Service.new(:access_key_id => key_id, :secret_access_key => key_secret)

		@logger.info "Getting bucket: #{bucket}"
		@bucket = @s3.buckets.find(bucket) or fail "no buckte '#{bucket}' found"
	end

	def put_image(image_path, content_type, data)
		@logger.info "Putting image in bucket '#{@bucket.name}': #{image_path}"

		file = @bucket.objects.build(image_path)
		file.content_type = content_type
		file.content = data
		file.save

		"http://#{@bucket.name}.s3.amazonaws.com/#{image_path}"
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
httpimagestore-0.2.1 lib/httpimagestore/s3_service.rb