[sync] image uploading
This commit is contained in:
1 parent
18150e8b35
commit
7c2d4dfd62
2 files changed
+30
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
|
||||
from utils.fn import combine, lmap
|
||||
|
||||
|
||||
@@ -83,3 +85,23 @@ def list_images(provider, path):
|
||||
lambda ext: provider.type_filter(path, ext),
|
||||
image_types
|
||||
))
|
||||
|
||||
|
||||
def upload(file_path, relative_path):
|
||||
"""
|
||||
/path/to/file, /url/path -> https://static.shlisselburg.org/art/url/path
|
||||
:param file_path:
|
||||
:param relative_path:
|
||||
:return:
|
||||
"""
|
||||
files = {'file': open(file_path, 'rb')}
|
||||
url = 'https://static.shlisselburg.org/upload/art{}'.format(relative_path)
|
||||
r = requests.put(
|
||||
url=url,
|
||||
files=files,
|
||||
auth=('uploader', '1207690962638465')
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return url
|
||||
else:
|
||||
return None
|
||||
Reference in new issue
Block a user