| Server IP : 123.56.80.60 / Your IP : 216.73.216.78 Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586 User : SYSTEM ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/python/Lib/site-packages/upyun/ |
Upload File : |
# -*- coding: utf-8 -*-
import os
import time
from .modules.exception import UpYunClientException
from .modules.sign import make_policy, make_signature
from .modules.httpipe import cur_dt
class FormUpload(object):
def __init__(self, service, username, password,
auth_server, endpoint, hp):
self.service = service
self.username = username
self.password = password
self.auth_server = auth_server
self.hp = hp
self.host = endpoint
self.uri = '/%s/' % service
def upload(self, key, value, expiration, **kwargs):
expiration = expiration or 1800
expiration += int(time.time())
dt = cur_dt()
data = {
'service': self.service,
'expiration': expiration,
'save-key': key,
'date': dt,
}
data.update(kwargs)
policy = make_policy(data)
signature = make_signature(
username=self.username,
password=self.password,
auth_server=self.auth_server,
method='POST',
uri=self.uri,
date=dt,
policy=policy
)
postdata = {
'policy': policy,
'authorization': signature,
'file': (os.path.basename(value.name), value),
}
resp = self.hp.do_http_pipe('POST', self.host, self.uri,
files=postdata)
return self.__handle_resp(resp)
def __handle_resp(self, resp):
content = None
try:
content = resp.json()
except Exception as e:
raise UpYunClientException(e)
return content