本地文件上传

  • 接口:common/files/url
  • Method:POST
  • 数据格式:JSON
  • 限流信息:每小时1000次
  • 多语言环境:在接口请求头中添加Key为locale,Value值为语言环境,目前支持的语言有zh_CN(中文)、en_US(英文)、ja_JP(日文)、zh_TW(繁体),请选取其中一种
  • 接口说明:本地文件上传
  • 其他补充信息:

代码示例:

final String filePath = "/Users/zhaohao/IdeaProjects/standard-api/standard-service/src
            /main/resources/jpg/baidu.jpg";
        final String url = "https://topenapi.cloudpense.com/common/files/url";

        RestTemplate template = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("multipart/form-data");
        headers.setContentType(type);
        headers.set("access_token","85aea5d7-b5e8-446b-a084-441074789bf4");

        //设置请求体
        FileSystemResource resource = new FileSystemResource(filePath);
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        form.add("file", resource);

        HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(form, headers);

        String attachmentResponse = template.postForObject(url, files, String.class);

返回参数

字段名称 字段类型 字段描述
resCode Integer 响应状态码(见附录)
resMsg String 返回信息描述
data Array 上传成功结果数组
data[].fileName String 文件名
data[].fileURL String 文件地址

示例:

请求数据

{
    "file": "test.txt"
}

返回数据

{
    "resCode": 200000,
    "resMsg": "success",
    "data": {
        "attachment": {
            "attachmentURL": "out/2020/07-21/911bee4f-9e78-44d7-a35b-9168d7c81ecb.html"
        }
    }
}

results matching ""

    No results matching ""