创建`OSS_minio.py`并定义`upload_stream`和`download_stream`
```py
class OSS:
# Create a client with the MinIO server playground, its access key
# and secret key.
def __init__(self, host, username, password, bucket):
self.host = host
self.client = Minio(
host,
access_key=username,
secret_key=password,
secure=False
)
self.bucket = bucket
def upload_stream(self,remote_path,data):
try:
self.client.put_object(self.bucket,remote_path,data,-1,part_size=5*1024*1024)
print(
"file is successfully uploaded as \n object %s to bucket %s." % (
remote_path, self.bucket)
)
address = 'http://'+self.host+'/'+self.bucket+'/'+remote_path
print(address)
return address
except S3Error as exc:
print("error occurred.", exc)
def download_stream(self, remote_path):
try:
response = self.client.get_object(self.bucket, remote_path)
return response
except S3Error as exc:
print("error occurred.", exc)
def init():
host = ""
username = ""
password = ""
bucket = ""
return OSS(host, username, password, bucket)
```
创建文件`templates/index.html`
```html
Transfery
0 Comments latest
No comments.