def __save_file(self, key, content, filename, content_type=None): if filename: filename = percent_encode(filename, safe='!#$&+-.^_`|~', encoding='utf-8') key.set_metadata('content-type', content_type) key.set_metadata( 'x-depot-filename', filename ) key.set_metadata('x-depot-modified', utils.timestamp()) key.set_metadata( 'Content-Disposition', make_content_disposition('inline', filename)) if hasattr(content, 'read'): can_seek_and_tell = True try: pos = content.tell() content.seek(pos) except: can_seek_and_tell = False if can_seek_and_tell: key.set_contents_from_file(content, policy=self._policy, encrypt_key=self._encrypt_key) else: key.set_contents_from_string(content.read(), policy=self._policy, encrypt_key=self._encrypt_key) else: if isinstance(content, unicode_text): raise TypeError('Only bytes can be stored, not unicode') key.set_contents_from_string(content, policy=self._policy, encrypt_key=self._encrypt_key)
def __save_file(self, key, content, filename, content_type=None): if filename: filename = percent_encode(filename, safe='!#$&+-.^_`|~', encoding='utf-8') attrs = { 'ACL': self._policy, 'StorageClass': self._storage_class, 'Metadata': { 'x-depot-filename': filename, 'x-depot-modified': utils.timestamp() }, 'ContentType': content_type, 'ContentDisposition': make_content_disposition('inline', filename) } if hasattr(content, 'read'): try: pos = content.tell() content.seek(pos) except: content = content.read() key.put(Body=content, **attrs) else: if isinstance(content, unicode_text): raise TypeError('Only bytes can be stored, not unicode') key.put(Body=content, **attrs)
def __save_file(self, key, content, filename, content_type=None): key.set_metadata('content-type', content_type) key.set_metadata('x-depot-filename', filename) key.set_metadata('x-depot-modified', utils.timestamp()) key.set_metadata('Content-Disposition', make_content_disposition('inline', filename)) if hasattr(content, 'read'): can_seek_and_tell = True try: pos = content.tell() content.seek(pos) except: can_seek_and_tell = False # excluding BufferedRandom just because boto3 doens't support BufferedRandom input if can_seek_and_tell and not isinstance(content, BufferedRandom): key.set_contents_from_file(content, policy=self._policy, encrypt_key=self._encrypt_key) else: key.set_contents_from_string(content.read(), policy=self._policy, encrypt_key=self._encrypt_key) else: if isinstance(content, unicode_text): raise TypeError('Only bytes can be stored, not unicode') key.set_contents_from_string(content, policy=self._policy, encrypt_key=self._encrypt_key)
def __save_file(self, key, content, filename, content_type=None): attrs = { 'ACL': self._policy, 'Metadata': { 'x-depot-filename': filename, 'x-depot-modified': utils.timestamp() }, 'ContentType': content_type, 'ContentDisposition': make_content_disposition('inline', filename) } if hasattr(content, 'read'): try: pos = content.tell() content.seek(pos) except: content = content.read() key.put(Body=content, **attrs) else: if isinstance(content, unicode_text): raise TypeError('Only bytes can be stored, not unicode') key.put(Body=content, **attrs)