Skip to content

Commit

Permalink
make case attachments with S3 work
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Sep 13, 2016
1 parent d46dfa6 commit ec2781f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions corehq/form_processor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,17 @@ class AbstractAttachment(DisabledDbMixin, models.Model, SaveStateMixin):
properties = JSONField(default=dict)

def write_content(self, content):
info = self._put_blob(content)
self.md5 = info.md5_hash
self.content_length = info.length
self.blob_id = info.identifier

def _put_blob(self, content):
if not self.name:
raise InvalidAttachment("cannot save attachment without name")

db = get_blob_db()
bucket = self._blobdb_bucket()
info = db.put(content, self.name, bucket)
self.md5 = info.md5_hash
self.content_length = info.length
self.blob_id = info.identifier
return db.put(content, self.name, bucket)

def read_content(self, stream=False):
db = get_blob_db()
Expand Down Expand Up @@ -900,7 +902,12 @@ def copy_content(self, attachment):
self._blobdb_bucket(), self.blob_id
)
content = attachment.read_content(stream=True)
self.write_content(content)
with content:
info = self._put_blob(content)
self.blob_id = info.identifier
assert self.content_length == info.length
if self.md5 and info.md5_hash:
assert self.md5 == info.md5_hash

@classmethod
def from_case_update(cls, attachment):
Expand Down

0 comments on commit ec2781f

Please sign in to comment.