def run(self):
_, ext = path.splitext(self.filename)
try:
mime_type = types_map[ext]
except KeyError:
mime_type = "application/octet-stream"
with open(self.filepath, 'rb') as f:
data = f.read()
headers = {
"Accept" : "*/*",
"Accept-Encoding" : "gzip,deflate",
"Accept-Language" : "en-US,en;q=0.8",
"Connection" : "keep-alive",
"Content-Length" : len(data),
"Content-Type" : mime_type,
"Host" : "transfer.sh",
"Origin" : "https://transfer.sh",
"Referer" : "https://transfer.sh/",
"User-Agent" : "Mozilla/5.0",
"X_FILENAME" : self.filename
}
url = "https://transfer.sh/" + self.filename
req = request.Request(url, data=data, headers=headers, method="PUT")
try:
show_status_message("ShareFile: uploading file...")
with request.urlopen(req, timeout=10) as resp:
if resp.status == 200:
body = resp.read()
share_link = body.decode('utf-8').strip('\n')
msg = template.format(share_link, "")
else:
msg = template.format("Could not upload file",
str(resp.status) + " " + resp.reason)
clear_status_message()
show_alert(msg)
except URLError as e:
msg = template.format(e.reason, "")
show_alert(msg)
评论列表
文章目录