各大图床 API - GXUZF.COM - 林澈思的茶

各大图床 API

分类:折腾 ; 热度:139 ; 最后更新于2020 年 03 月 28 日

赵帆同学赵帆同学

最近上线了伏安私有云网盘服务,为了扩充空间,搜集了一些图床的API接口

百度

百度识图的接口

    func UploadToBaidu(img []byte, imgInfo string) string {
        body := new(bytes.Buffer)
        w := multipart.NewWriter(body)
        contentType := w.FormDataContentType()
        name := utils.GetFileNameByMimeType(imgInfo)
        file, _ := w.CreateFormFile("Filedata", name)
        _, _ = file.Write(img)
        _ = w.WriteField("file", "multipart")
        _ = w.Close()
        req, _ := http.NewRequest("POST", "https://api.uomg.com/api/image.baidu", body)
        req.Header.Set("Content-Type", contentType)
        resp, _ := http.DefaultClient.Do(req)
        defer resp.Body.Close()
        data, _ := ioutil.ReadAll(resp.Body)
        baidu := bed.BaiduResp{}
        err := json.Unmarshal([]byte(string(data)), &baidu)
        if err != nil {
            logging.AppLogger.Error("Upload To Baidu fail", zap.Error(err))
            return ""
        }
        return string(baidu.ImgUrl)
    }

奇虎360(Qihoo)

    func UploadToQihoo(img []byte, imgInfo string, imgType string) string {
        url := "http://st.so.com/stu"
        name := utils.GetFileNameByMimeType(imgInfo)
        file := &utils.FormFile{
            Name:  name,
            Key:   "upload",
            Value: img,
            Type:  imgType,
        }
        var header map[string]string
        data := utils.FormPost(file, url, header)
        var re = regexp.MustCompile(`(?m)data-imgkey="(.*)"`)
        imgKey := re.FindAllStringSubmatch(data, -1)[0][2]
        url = "https://ps.ssl.qhmsg.com/" + imgKey
        return url
    }

网易严选(NetEasy)

    func UploadToNetEasy(img []byte, imgInfo string, imgType string) string {
        url := "http://you.163.com/xhr/file/upload.json"
        name := utils.GetFileNameByMimeType(imgInfo)
        file := &utils.FormFile{
            Name:  name,
            Key:   "file",
            Value: img,
            Type:  imgType,
        }
        var header map[string]string
        data := utils.FormPost(file, url, header)
        netEasy := bed.NetEasyResp{}
        _ = json.Unmarshal([]byte(data), &netEasy)
        return netEasy.Data[0]
    }

京东(JD)

    func UploadToJd(img []byte, imgInfo string, imgType string) string {
        url := "https://search.jd.com/image?op=upload"
        name := utils.GetFileNameByMimeType(imgInfo)
        file := &utils.FormFile{
            Name:  name,
            Key:   "file",
            Value: img,
            Type:  imgType,
        }
        var header map[string]string
        data := utils.FormPost(file, url, header)
        var pre = regexp.MustCompile(`(?m)ERROR`)
        if !pre.MatchString(data) {
            var re = regexp.MustCompile(`(?m)\("(.*)"\)`)
            imgFix := re.FindAllStringSubmatch(data, -1)[0][3]
            url = "https://img" + strconv.Itoa(rand.Intn(3)+11) + ".360buyimg.com/img/" + imgFix
            return url
        } else {
            return ""
        }
    }

掘金(JueJin)

    func UploadToJueJin(img []byte, imgInfo string, imgType string) string {
        url := "https://cdn-ms.juejin.im/v1/upload?bucket=gold-user-assets"
        name := utils.GetFileNameByMimeType(imgInfo)
        file := &utils.FormFile{
            Name:  name,
            Key:   "file",
            Value: img,
            Type:  imgType,
        }
        var header map[string]string
        data := utils.FormPost(file, url, header)
        juejin := bed.JueJinResp{}
        _ = json.Unmarshal([]byte(data), &juejin)
        //神奇三断言 : )
        reJ, _ := juejin.D.(map[string]interface{})
        urls, _ := reJ["url"].(map[string]interface{})
        httpUrl, _ := urls["https"].(string)
        return httpUrl
    }

阿里(Ali)

    func UploadToAli(img []byte, imgInfo string, imgType string) string {
        url := "https://kfupload.alibaba.com/mupload"
        name := utils.GetFileNameByMimeType(imgInfo)
        file := &utils.FormFile{
            Name:  name,
            Key:   "file",
            Value: img,
            Type:  imgType,
        }
        //var header map[string]string
        data := utils.AliFormPost(file, url)
        ali := bed.AliResp{}
        _ = json.Unmarshal([]byte(data), &ali)
        return ali.Url
    }

转载自白云の点滴记忆


评论卡