Ejemplo n.º 1
0
    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 get_key(self):
     '''
         cbuimgsearch/Z5Qja4fXPH1562293605000.jpg 生成规则是 cbuimgsearch/ + 随机10位 + 毫秒级别时间戳
         :return:
         '''
     key = "cbuimgsearch/" + "".join(get_random_str(10)) + str(int(time.time() * 1000))
     return key
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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, 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
Ejemplo n.º 7
0
    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