def upload_img(self, filename): """ 用于上传图片 :return: """ name = get_random_str(5) + ".jpeg" if os.path.exists(filename): bytestream = open(filename, "rb").read() else: us = urlparse(filename) if not us: return 'fail', None r = requests.get(filename) bytestream = io.BytesIO(r.content) files = { "name": (None, name), # "ua": (None, ""), "file": (name, bytestream) } status, res = request_post(self.upload_url, data=None, files=files, headers=self.headers) key = "" if status == "succ": data = json.loads(res) url = data["object"]["url"] key = url.split("/")[-1] return status, key
def upload_img(self, filename, signature, policy, accessid): """ 用于上传图片 :return: """ url = 'https://cbusearch.oss-cn-shanghai.aliyuncs.com/' key = "cbuimgsearch/" + get_random_str(10) + str(int(time.time()) * 1000) + ".jepg" name = get_random_str(5) + ".jpeg" if os.path.exists(filename): bytestream = open(filename, "rb").read() else: us = urlparse(filename) if not us: return 'fail', None r = requests.get(filename) bytestream = io.BytesIO(r.content) files = { "name": (None, name), "key": (None, key), "policy": (None, policy), "OSSAccessKeyId": (None, accessid), "success_action_status": (None, 200), "callback": (None, ""), "signature": (None, signature), "file": (name, bytestream) } status, res = request_post(url, data=None, files=files, headers=self.headers) return status, key
def upload_img(self, filename): url = "https://search.jd.com/image?op=upload" files = { "file": (get_random_str(5) + ".jpg", open(filename, "rb").read()), } status, data = request_post(url, files=files, headers=self.headers) return status, data
def upload_img(self, filename): url = "https://s.taobao.com/image" files = { "cross": (None, "taobao"), "type": (None, "iframe"), "imgfile": (get_random_str(5) + ".jpg", open(filename, "rb").read(), "image/jpeg"), } status, data = request_post(url, files=files, headers=self.headers) return status, data
def upload_img(self, filename): url = "https://s.taobao.com/image" if os.path.exists(filename): bytestream = open(filename, "rb").read() else: us = urlparse(filename) if not us: return 'fail', None r = requests.get(filename) bytestream = io.BytesIO(r.content) files = { "cross": (None, "taobao"), "type": (None, "iframe"), "imgfile": (get_random_str(5) + ".jpg", bytestream, "image/jpeg"), } status, data = request_post(url, files=files, headers=self.headers) return status, data
def upload_img(self, filename, signature, policy, accessid): """ 用于上传图片 :return: """ url = 'https://cbusearch.oss-cn-shanghai.aliyuncs.com/' key = "cbuimgsearch/" + get_random_str(10) + str(int(time.time() * 1000)) name = get_random_str(5) + ".jpg" files = { "name": (None, name), "key": (None, key), "policy": (None, policy), "OSSAccessKeyId": (None, accessid), "success_action_status": (None, 200), "callback": (None, ""), "signature": (None, signature), "file": (name, open(filename, "rb").read()) } status, res = request_post(url, files=files, headers=self.headers) return status, key