Browse Source

Update 'README.md'

天问 1 month ago
parent
commit
02bb4b4374
1 changed files with 19 additions and 0 deletions
  1. 19 0
      README.md

+ 19 - 0
README.md

@@ -6,5 +6,24 @@
 ```
 pip install boto3
 
+s3 = boto3.client('s3', endpoint_url=config.AWS_ENDPOINT_URL_S3)
+
+def upload(name: str, data: str):
+    gzip_buffer = BytesIO()
+    with gzip.GzipFile(mode='wb', fileobj=gzip_buffer) as gzip_file:
+        gzip_file.write(data.encode('utf-8'))
+    return s3.put_object(
+        Bucket=config.BUCKET_NAME,
+        Key=name,
+        Body=gzip_buffer.getvalue(),
+        ContentEncoding='gzip',
+        ContentType='application/json'
+    )
+
+def download(name: str) -> str:
+    response = s3.get_object(Bucket=config.BUCKET_NAME, Key=name)
+    gzip_content = response['Body'].read()
+    return gzip.decompress(gzip_content)
+    
 ```