forked from xcloudlive/flask-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alioss.py
34 lines (29 loc) · 956 Bytes
/
alioss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import base64
import uuid
import oss2
import os
myAccessKeyId = os.environ.get("myAccessKeyId")
myAccessKeySecret = os.environ.get("myAccessKeySecret")
EndPoint = 'oss-cn-qingdao.aliyuncs.com'
myBucketName = 'sunlingfeng'
myBucketUrl = 'http://sunlingfeng.0431zy.com/'
def upload(filename: object, cloud_name: object) -> object:
auth = oss2.Auth(myAccessKeyId, myAccessKeySecret)
bucket = oss2.Bucket(auth, EndPoint, myBucketName)
with open(oss2.to_unicode(filename), 'rb') as f:
bucket.put_object(cloud_name, f)
meta = bucket.get_object_meta(cloud_name)
print(meta)
if meta:
return myBucketUrl + cloud_name
else:
return ''
def uploadBase64(base64STR):
imgData = base64.b64decode(str(base64STR))
filename = str(uuid.uuid4()) + '.jpg'
file = open(filename, 'wb')
file.write(imgData)
file.close()
fileUrl = upload(filename, filename)
os.remove(filename)
return fileUrl