Commit 677e7b58 authored by Elouan Martinet's avatar Elouan Martinet
Browse files

[storages] Add the ability to set upload extra args

parent 8b4ec082c4b9
Pipeline #36566 failed with stage
in 1 minute and 30 seconds
......@@ -98,7 +98,9 @@ class S3Storage(Storage):
buffer = Binary(
suffixed_key = self.suffixed_key(key)
self.s3cnx.upload_fileobj(buffer, self.bucket, suffixed_key)
extra_args = self.get_upload_extra_args(entity, attr, key)
self.s3cnx.upload_fileobj(buffer, self.bucket, suffixed_key,
# move to final key in post commit event
......@@ -108,6 +110,13 @@ class S3Storage(Storage):
entity.eid, attr, self.bucket, suffixed_key)
return binary
def get_upload_extra_args(self, _entity, _attr, _key):
"""Additional options for boto3's upload_fileobj method.
Documentation for supported options can be found at:
return {}
def entity_updated(self, entity, attr):
"""an entity using this storage for attr has been updatded"""
return self.entity_added(entity, attr)
import re
from contextlib import contextmanager
from mock import patch
from six import PY3
......@@ -88,6 +89,21 @@ class S3StorageTC(testing.S3StorageTestMixin, CubicWebTC):
keys = [x.key for x in self.s3_bucket.objects.all()]
self.assertNotIn(key, keys)
def test_upload_content_type(self):
mime_type = 'x-custom/mime-type'
with self.admin_access.client_cnx() as cnx, \
return_value={'ContentType': mime_type}):
image = create_image(cnx, b'some content')
s3storage ='Image', 'data')
s3_key = s3storage.get_s3_key(image, 'data')
head = s3storage.s3cnx.head_object(,
self.assertEqual(head['ContentType'], mime_type)
class S3StorageMigrationTC(testing.S3StorageTestMixin, CubicWebTC):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment