获取文件上传地址

  • 接口:common/files/v3/uploadUrl
  • Method:POST
  • 数据格式:JSON
  • 限流信息:每小时1000次
  • 接口说明:本接口为批量接口,接口返回成功不代表全部处理成功。具体参见示例
  • 变更历史

参数

请求参数

字段名称 字段类型 字段描述 是否必填 备注
bizId String 业务唯一识别码 true 长度不超过64
timestamp Long 时间戳 true
data Array 文件名数组 TRUE 数组长度不超过100
data.file_name String 文件名 TRUE 必须包含文件后缀名

返回参数

字段名称 字段类型 字段描述
bizId String 业务唯一识别码
timestamp Long 时间戳
resCode Integer 响应状态码(见附录)
resMsg String 返回信息描述
data Array 处理成功的结果数组
data[].file_name String 文件名
data[].upload_url String 文件上传地址,有效期2小时
data[].attachment_url String 附件地址

示例

请求数据

{
  "bizId": "2c1ece50-3cab-4f1c-a5d9-fd297afdd1e2",
  "timestamp": 1744252563000,
  "data": [
    {
      "file_name": "test.png"
    },
    {
      "file_name": "test.pdf"
    }
  ]
}

返回数据

全部处理成功返回

{
  "resCode": 200000,
  "resMsg": "success",
  "bizId": "2c1ece50-3cab-4f1c-a5d9-fd297afdd1e2",
  "data": [
    {
      "file_name": "test.png",
      "upload_url": "https://xxx/cc28cda9-836c-493f-81c8-7e23d78cdf2f.png?xxxx",
      "attachment_url": "cc28cda9-836c-493f-81c8-7e23d78cdf2f.png"
    },
    {
      "file_name": "test.pdf",
      "upload_url": "https://xxxx/a2244808-ad23-437d-98b3-c0318e26a115.pdf?xxxxx",
      "attachment_url": "a2244808-ad23-437d-98b3-c0318e26a115.pdf"
    }
  ]
}

部分处理成功返回

{
  "resCode": 200000,
  "resMsg": "success",
  "bizId": "2c1ece50-3cab-4f1c-a5d9-fd297afdd1e2",
  "data": [
    {
      "file_name": "test.png",
      "upload_url": "https://xxx/cc28cda9-836c-493f-81c8-7e23d78cdf2f.png?xxxx",
      "attachment_url": "cc28cda9-836c-493f-81c8-7e23d78cdf2f.png"
    }
  ]
}

全部处理失败返回

{
  "resCode": 200000,
  "resMsg": "success",
  "bizId": "2c1ece50-3cab-4f1c-a5d9-fd297afdd1e2",
  "data": []
}

代码示例

使用文件上传地址上传文件

也可以参考各对象存储的使用签名URL临时授权上传文件的相关示例

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.File;
import java.io.IOException;

public class Test {
    public static void main(String[] args) throws IOException {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        String pathName = "test.pdf";
        URL signedUrl = new URL("https://xxxxxx.amazonaws.com.cn/6307ced9-c793-450f-a2a5-5c4f615619af.pdf?xxxxx");
        try {
            HttpPut put = new HttpPut(signedUrl.toString());
            HttpEntity entity = new FileEntity(new File(pathName));
            put.setEntity(entity);

            // 注意:阿里云oss和华为云obs 暂不支持设置
            // 获取文件 MIME 类型
            String mimeType = Files.probeContentType(Paths.get(pathName));
            if (mimeType == null) {
                mimeType = "application/octet-stream";
            }

            // 设置 Content-Type
            put.setHeader("Content-Type", mimeType);
            httpClient = HttpClients.createDefault();
            response = httpClient.execute(put);

            System.out.println("返回上传状态码:" + response.getStatusLine().getStatusCode());
            if (response.getStatusLine().getStatusCode() == 200) {
                System.out.println("上传成功");
            }
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                response.close();
            }
            if (httpClient != null) {
                httpClient.close();
            }
        }
    }
}

变更历史

变更日期 变更人 变更描述
2025-04-28 李鹏飞 新建密钥信息

历史版本

历史接口 下线日期 描述
获取附件上传地址 2025-01-01 定义偏差,定义了驼峰字段

results matching ""

    No results matching ""