Merge pull request #174 from grindtildeath/12.0_attachment_s3_bin_size_close

[12.0] attachment_s3: Improvements
This commit is contained in:
Guewen Baconnier
2020-06-22 07:45:26 +02:00
committed by GitHub
co-authored by GitHub
+4 -2
View File
@@ -122,7 +122,9 @@ class IrAttachment(models.Model):
bucket.meta.client.head_object( bucket.meta.client.head_object(
Bucket=bucket.name, Key=key Bucket=bucket.name, Key=key
) )
res = io.BytesIO() if bin_size:
return bucket.Object(key).content_length
with io.BytesIO() as res:
bucket.download_fileobj(key, res) bucket.download_fileobj(key, res)
res.seek(0) res.seek(0)
read = base64.b64encode(res.read()) read = base64.b64encode(res.read())
@@ -141,7 +143,7 @@ class IrAttachment(models.Model):
if location == 's3': if location == 's3':
bucket = self._get_s3_bucket() bucket = self._get_s3_bucket()
obj = bucket.Object(key=key) obj = bucket.Object(key=key)
file = io.BytesIO() with io.BytesIO() as file:
file.write(bin_data) file.write(bin_data)
file.seek(0) file.seek(0)
filename = 's3://%s/%s' % (bucket.name, key) filename = 's3://%s/%s' % (bucket.name, key)