@@ -25,6 +25,18 @@ def md5sum(data):
25
25
return h .hexdigest ()
26
26
27
27
28
+ # need pyocclient-0.3 release
29
+ class OwnCloudFileStor (FileStore ):
30
+ def __init__ (self ):
31
+ return
32
+
33
+ def uploadData (data ):
34
+ return
35
+
36
+ def uploadFile (fname ):
37
+ return
38
+
39
+
28
40
class QiniuFileStore (FileStore ):
29
41
def __init__ (self ):
30
42
return
@@ -39,21 +51,24 @@ def uploadData(data):
39
51
secret_key = qiniu_seckey
40
52
bucket_name = qiniu_bucket_name
41
53
54
+ print (access_key , secret_key , bucket_name )
42
55
q = qiniu .Auth (access_key , secret_key )
56
+ # 由于本机时间错误,导致计算了出的token立即失效:
57
+ # text_body:{"error":"expired token"}
58
+ token = q .upload_token (bucket_name , expires = 3600 * 24 )
43
59
key = 'helloqt.png'
44
60
key = FileStore .md5sum (data )
45
61
# data = 'hello qiniu!'
46
62
# data = load_from_file(PATH)
47
- token = q .upload_token (bucket_name )
48
- print ('uploading file:' , key )
63
+ print ('uploading file:' , key , token )
49
64
ret , info = qiniu .put_data (token , key , data )
50
65
if ret is not None :
51
66
print ('upload file All is OK' , ret )
67
+ url = 'http://7xn2rb.com1.z0.glb.clouddn.com/%s' % key
68
+ return url
52
69
else :
53
70
print (ret , '=====' , info ) # error message in info
54
-
55
- url = 'http://7xn2rb.com1.z0.glb.clouddn.com/%s' % key
56
- return url
71
+ return str (info )
57
72
58
73
def uploadFile (fname ):
59
74
data = b''
@@ -63,6 +78,11 @@ def uploadFile(fname):
63
78
return QiniuFileStore .uploadData (data )
64
79
65
80
81
+ def _test_qiniu_upload ():
82
+ u = QiniuFileStore .uploadData ('aaaaaaaaaaaaaaaaaaaaaaa' .encode ())
83
+ print (u )
84
+
85
+
66
86
class ImgurFileStore (FileStore ):
67
87
def __init__ (self ):
68
88
return
@@ -139,7 +159,7 @@ def __init__(self):
139
159
return
140
160
141
161
def uploadData (data ):
142
- # return 'nourl'
162
+ return 'nourl'
143
163
if type (data ) == QByteArray :
144
164
data = data .data ()
145
165
@@ -184,3 +204,4 @@ def uploadFile(fname):
184
204
if not url .startswith ('https://' ): print ('upload error: ' , hdrval .getvalue ())
185
205
186
206
return url
207
+
0 commit comments