28 lines
732 B
Python
28 lines
732 B
Python
import os
|
|
import io
|
|
import time
|
|
import random
|
|
import requests
|
|
|
|
def upload_image(image2_data, domain: str):
|
|
image_stream = io.BytesIO(image2_data)
|
|
headers = {
|
|
'Token': 'fangzhouxinghe'
|
|
}
|
|
data = {
|
|
'domain': domain
|
|
}
|
|
files = {
|
|
'file': (f'{time.time()}_{random.randint(10000, 99999)}.jpg', image_stream, 'image/jpeg')
|
|
}
|
|
|
|
response = requests.post('https://fangzhouxinghe.com/uploads.php', data=data, headers=headers, files=files)
|
|
response_data = response.json()
|
|
|
|
if response_data['code'] != 200:
|
|
raise Exception(response_data['msg'])
|
|
return response_data['data']
|
|
|
|
if __name__ == '__main__':
|
|
print(upload_image(open(r"test\50137.jpg", 'rb').read(), 'test'))
|