Account Package Upload API

Last updated: 2021-04-25 15:57:58

    API Description

    Request method: POST

    Service URL/v3/push/package/upload
    

    API service URLs correspond to service access points one to one. Please select the service URL corresponding to the service access point of your application.

    Feature: you can upload a package of multiple accounts and push to the accounts in batches. The two main APIs used are the account package upload API and the account package push API.

    Note:

    • Account package file name: [1, 100] characters
    • Account package format and size: .zip, .txt, or .csv file within 100 MB
    • .zip file requirements: can contain single .txt or .csv files but not folders
    • .txt file requirements: encoded in UTF-8; one account ([2, 100] characters) per row
    • .csv file requirements: one column only; one account ([2, 100] characters) per row

    Request Parameters

    Parameter Type Required Description
    file form-data Yes
  • Account package format and size: .zip, .txt, or .csv file within 100 MB
  • .zip file requirements: can contain single .txt or .csv files but not folders
  • .txt file requirements: encoded in UTF-8; one account ([2, 100] characters) per row
  • .csv file requirements: one column only; one account ([2, 100] characters) per row
  • Response Parameters

    Parameter Type Required Description
    retCode Integer Yes Error code
    errMsg String Yes Error message of a request error
    uploadId Integer Yes When a file is uploaded, a positive integer is returned, which represents the ID of the uploaded file (uploadId). It is provided to the push API for account package push.

    Sample Request

    Python3

    import base64
    from pip._vendor import requests
    from pip._vendor.urllib3 import encode_multipart_formdata
    
    def upload(url, filePath, accessId, secret, data={}, header={}):
        openFile = open(filePath, 'rb')
        data['file'] = (openFile.name, openFile.read())
        encode_data = encode_multipart_formdata(data)
        data = encode_data[0]
        header['Content-Type'] = encode_data[1]
        authInfo = accessId + ":" + secret
    
        header['Authorization'] = "Basic " + str(base64.b64encode(bytes(authInfo, encoding="utf8")),encoding="utf8")
        
        r = requests.post(url, headers=header, data=data)
        print(r.json())
    

    Golang

    func Upload(url string, filePath string, accessId string, secret string)(resp string , err error) {
        fp, err := os.Open(filePath)
        if err != nil {
            return resp, err
        }
        defer fp.Close()
        body := &bytes.Buffer{}
        writer := multipart.NewWriter(body)
        defer writer.Close()
        part, err := writer.CreateFormFile("file", filepath.Base(fp.Name()))
        if err != nil {
            return resp, err
        }
        io.Copy(part, fp)
        writer.Close()
        httpReq, err := http.NewRequest(http.MethodPost, url, body)
        if err != nil {
            return resp, err
        }
        
        httpReq.Header.Add("Content-Type", writer.FormDataContentType())
        
        authInfo := base64.StdEncoding.EncodeToString([]byte(accessId + ":" + secret))
        httpReq.Header.Add("Authorization", fmt.Sprintf("Basic %s", authInfo))
        cli := &http.Client{}
        httpResp, err := cli.Do(httpReq)
        if err != nil {
            return resp, err
        }
        defer httpResp.Body.Close()
        data, err := ioutil.ReadAll(httpResp.Body)
        if err != nil {
            return resp, err
        }
        if httpResp.StatusCode != http.StatusOK {
            return resp, fmt.Errorf("response error, status: %s, body: %s", httpResp.Status, string(data))
        }
        
        resp = string(data)
        return resp, nil
    }
    

    C#

            public string Upload(string url, string filePath, uint accessId, string secretKey)
            {
                var tmp = accessId.ToString() + ":" + secretKey;
                var sign = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(tmp));
                MultipartFormDataContent form = new MultipartFormDataContent();
                var content = new StreamContent(new FileStream(filePath, FileMode.Open));
                content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "file",
                    FileName = Path.GetFileName(filePath)
                };
                form.Add(content);
                using(HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Add("Authorization","Basic " + sign);
                    client.DefaultRequestHeaders.ExpectContinue = true;
                    var response = (client.PostAsync(url, form)).Result;
                    var result = response.Content.ReadAsStringAsync().Result;
                    if (response.StatusCode != HttpStatusCode.OK) {
                        throw new Exception(result);
                    }
                    return result;
                }
            }
    

    PHP

    function upload($url, $file, $accessId, $secretkey) {
        $sign = base64_encode($accessId . ":" . $secretKey);
        $headers = array("Content-type: multipart/form-data", "Authorization: Basic " . $sign);
        $cfile = new \CURLFile($file,'multipart/form-data',basename($file));
        $options = array(
            CURLOPT_HTTPHEADER      => $headers,
            CURLOPT_HEADER          => 0,
            CURLOPT_SSL_VERIFYPEER  => false,
            CURLOPT_SSL_VERIFYHOST  => 0,
            CURLOPT_POST            => 1,
            CURLOPT_URL             => $url,
            CURLOPT_RETURNTRANSFER  => 1,
            CURLOPT_TIMEOUT         =>