Commit dafa859e

mo khan <mo@mokhan.ca>
2014-06-07 23:53:13
give s3 uploads read access to everyone.
1 parent f303d3b
Changed files (2)
app
services
infrastructure
spec
services
infrastructure
app/services/infrastructure/blob_storage.rb
@@ -8,7 +8,8 @@ class BlobStorage
   def upload(key, file)
     puts "uploading to #{bucket_name}/#{key}"
     object = connection.buckets[bucket_name].objects[key]
-    object.write(Pathname.new(file), content_type: content_type_for(file), cache_control: 'public, max-age=315576000')
+    object.write(Pathname.new(file), options_for(file))
+    object.acl = :public_read
   end
 
   private
@@ -21,6 +22,13 @@ class BlobStorage
     ::MIME::Types.type_for(file).first.to_s
   end
 
+  def options_for(file)
+    {
+      content_type: content_type_for(file),
+      cache_control: 'public, max-age=315576000',
+    }
+  end
+
   class Fake
     def upload(*args)
     end
spec/services/infrastructure/blob_storage_spec.rb
@@ -12,7 +12,7 @@ describe BlobStorage do
       subject.upload(key, file)
 
       object = AWS::S3.new.buckets[bucket].objects[key]
-      expect(object.size).to > 0
+      expect(object.exists?).to be_true
     end
   end
 end