'Upload file to S3 storage'

def persist_file(self, path, buf, info, meta=None, headers=None):

    key_name = ('%s%s' % (self.prefix, path))
    buf.seek(0)
    if self.is_botocore:
        extra = self._headers_to_botocore_kwargs(self.HEADERS)
        if headers:
            extra.update(self._headers_to_botocore_kwargs(headers))
        return threads.deferToThread(self.s3_client.put_object, Bucket=self.bucket, Key=key_name, Body=buf, Metadata={k: str(v) for (k, v) in six.iteritems((meta or {}))}, ACL=self.POLICY, **extra)
    else:
        b = self._get_boto_bucket()
        k = b.new_key(key_name)
        if meta:
            for (metakey, metavalue) in six.iteritems(meta):
                k.set_metadata(metakey, str(metavalue))
        h = self.HEADERS.copy()
        if headers:
            h.update(headers)
        return threads.deferToThread(k.set_contents_from_string, buf.getvalue(), headers=h, policy=self.POLICY)
