Write Chunk File

通过指定通道,向数据源写入块文件。

前提条件

已创建数据写入通道,且通道已启动。

请求格式

POST https://{apigw-address}/data-federation/v2.0/channels/write/{channelId}/chunk-file

请求参数(URI)

名称

位置(Path/Query)

必需/可选

数据类型

描述

orgId

Query

必需

String

用户所属的组织ID。如何获取orgId信息>>

channelId

Path

必需

String

通道ID。

dataSourceName

Query

必需

String

数据源别名,目前仅支持HDFS数据源。

请求参数(Body)

名称

必需/可选

数据类型

描述

fileName

必需

String

待写入的文件名。

totalSize

必需

Integer

文件大小。

chunkOffset

必需

Integer

当前块在文件中的偏移。

chunkSize

必需

Integer

当前块大小(base64编码之前的大小)。

chunkData

必需

String

块数据,需要进行Base64编码。

示例

请求示例

url: https://{apigw-address}/data-federation/v2.0/channels/write/{channelId}/chunk-file?orgId={}&dataSourceName={}

method: POST

requestBody:
{
  "fileName": "ttt",
  "totalSize": "13",
  "chunkData": "dGVzdHRlc3R0dGVzdA==",
  "chunkSize": "13",
  "chunkOffset": "0"
}

返回示例

{
  "msg": "OK",
  "code": 0,
  "submsg": ""
}

Java SDK调用示例

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import com.google.common.net.HttpHeaders;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Sample {

    private static String accessKey = "AccessKey of your APP";
    private static String secretKey = "SecretKey of your APP";
    private static String orgId = "yourOrgId";
    private static String chId = "yourChannelId";
    private static String url = "https://{domain_url}";

    private static class Request extends PoseidonRequest {

        public void setQueryParam(String key, Object value) {
            queryEncodeParams().put(key, value);
        }

        public void setMethod(String method) {
            this.method = method;
        }

        public void setBodyParams(String key, Object value) {
            bodyParams().put(key, value);
        }

        private String method;

        @Override
        public String baseUri() {
            return "";
        }

        @Override
        public String method() {
            return method;
        }
    }

    @Test
    public void writeChunkFile() {
        Request request = new Request();
        request.setQueryParam("orgId", orgId);
        request.setQueryParam("dataSourceName", "hdfs");
        request.setMethod("POST");
        request.headerParams().put(HttpHeaders.CONTENT_TYPE, "application/json");
        request.setBodyParams("fileName", "ttt");
        request.setBodyParams("totalSize", "13");
        request.setBodyParams("chunkData", "dGVzdHRlc3R0dGVzdA==");
        request.setBodyParams("chunkSize", "13");
        request.setBodyParams("chunkOffset", 0);
        try {
            JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                    .url(url + "/data-federation/v2.0/channels/write/" + chId + "/chunk-file")
                    .getResponse(request, JSONObject.class);
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}