neoark
Chevereto Member
Hello,
It seems like when I try to post an image via API it is using guest limits {"status_code":400,"error":{"message":"File too big - max 1 MB","code":313,"context":"CHV\\UploadException"},"status_txt":"Bad Request"} .
I am using the custom route with API user upload https://chevereto.com/docs/api-v1 .
// This will upload images to 'jesse' account
CHV\Image::uploadToWebsite($source, 'jesse');
Here is the sample code to post to API
It seems like when I try to post an image via API it is using guest limits {"status_code":400,"error":{"message":"File too big - max 1 MB","code":313,"context":"CHV\\UploadException"},"status_txt":"Bad Request"} .
I am using the custom route with API user upload https://chevereto.com/docs/api-v1 .
// This will upload images to 'jesse' account
CHV\Image::uploadToWebsite($source, 'jesse');
Here is the sample code to post to API
Python:
#coding=utf-8
import requests
import json
import mimetypes
from PIL import ImageGrab
import datetime
def upload(files):
APIKey = "YOUR API KEY"
format = "json"
url = "http://domain.com/api/1/upload/?key="+ APIKey + "&format=" + format
#files =
r = requests.post(url , files = files)
return json.loads(r.text)
def formatSource(filename):
imageList = []
type = mimetypes.guess_type(filename)[0]
imageList.append(('source' , (filename , open(filename , 'rb') , type)))
print imageList
return imageList
if __name__ == "__main__":
print "将图片截图或复制到剪切板中即可~~, ctrl+z 结束"
recentVal = None
while(True):
tmpValue = ImageGrab.grabclipboard()
if recentVal != tmpValue:
recentVal = tmpValue
now = datetime.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M:%S")
filename = 'IMG'+ now + '.png'
if recentVal is not None:
recentVal.save(filename, 'png')
#filenames.append(filename)
#recentVal = None
print filename
jsonData = upload(formatSource(filename))
if jsonData['status_code'] != 200:
print "error: " , jsonData['error']['message']
print "status code : " , jsonData['status_code']
else:
print "orignal url: " , jsonData['image']['display_url']
print "thumb url: " , jsonData['image']['thumb']['url']
