API Path
/aipaas/lm/v1/excel/addEx
请求协议
HTTP
请求方法
POST
请求头部:
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | application/json | application/json | ||
| X-APP-ID | 是 | 买家中心-已购能力-【X-APP-ID】 | [string] | ||||
| Device-Uuid | 否 | 设备管理-设备uuid | [string] | ||||
| Authorization | 是 | 鉴权信息 | [string] |
请求参数 表单
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| seq_id | 请求ID,最大长度为64 | 是 | [string] | |||
| file_bin | 文件二进制数据,建议10M以上文件使用该接口进行上传,最大支持上传500M | 是 | [file] | |||
| file_name | 文件名称,最大长度255 | 是 | [string] | |||
| file_type | 文件类型 ,可选值:"excel"、"csv"。.xlsx/.xls文件需要填写excel,.csv需要填写csv | 是 | [string] | |||
| file_md5 | 文件md5 | 否 | [string] |
响应内容:
返回结果
> 成功 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| code | 错误码 | 是 | [int] | |||
| message | 响应描述信息 | 是 | [string] | |||
| seq_id | 请求ID | 是 | [string] | |||
| file_uuid | 文件uuid | 是 | [string] |
成功示例[Mock API]:
{
"code": 10000,
"message": "ok",
"seq_id": "gfgigqhoqrg",
"file_uuid": "d12fd037-19df-4973-a246-290673b6407a"
}
失败示例[Mock API]:
{
"code": 10001,
"message": "文件格式错误",
"seq_id": "gfgigqhoqrg"
}
该接口用于添加需要后续进行表格理解分析的文档,当文档大于10M时建议使用该接口。若文档小于10M,建议使用文件上传接口。
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 签名认证方式。
curl --location --request POST 'http://ip:port/aipaas/lm/v1/excel/generate/addEx'
--header 'Content-Type: multipart/form-data'
--form 'file_bin=@'"$file"''
--form 'seq_id="gfgigqhoqrg"'
--form 'file_type="csv"'
--form 'file_name='"$file"''
--form 'file_md5='"$md5"''
通用状态码请参见【状态码】中的【网关认证】和【通用业务】, 接口相关状态码如下:
| 编码 | 描述信息 |
|---|---|
| 10000 | 正确返回 |
| 10001 | 文件读取错误或列表为空 |
| 10002 | 文件格式错误 |
| 10003 | base64解码错误 |
| 10004 | md5校验失败 |
| 10005 | 文件上传失败 |
| 10006 | 数据存储失败 |
| 10007 | csv或excel不是标准格式,解码失败 |
| 10008 | 检索文件id不存在 |
| 10009 | 删除文件id不存在 |
| 10010 | 删除文件失败 |
| 10011 | 上传文件为空 |
| 10012 | 文件上传解析失败 |
| 10013 | 未找到对应uuid的文件 |
| 10030 | 请求参数错误 |
| 19999 | 未知错误 |
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.IOException;
public class Example {
/**
* 引入依赖
*
* org.apache.httpcomponents
* httpclient
* 4.5.13
*
*
* org.apache.httpcomponents
* httpmime
* 4.5
*
*/
public static void main(String[] args) {
String url = "算法调用地址";
String appId = "uourAppId";
String appKey = "yourAppKey";
String orderNum = "yourOrderNum";
String seqId = "test12021545";
String fileName = "people_info.csv";
String fileType = "csv";
File file = new File("./people_info.csv");
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost post = new HttpPost(url);
// 设置头信息
post.setHeader("Content-Type", "multipart/form-data");
post.put("X-APP-ID", "yourAppId");
post.put("Authorization", "yourAuthorization");
// 设置 multipart entity
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("seq_id", seqId, ContentType.TEXT_PLAIN);
builder.addBinaryBody(
"file_bin",
file,
ContentType.APPLICATION_OCTET_STREAM,
fileName
);
builder.addTextBody("file_name", fileName, ContentType.TEXT_PLAIN);
builder.addTextBody("file_type", fileType, ContentType.TEXT_PLAIN);
HttpEntity multipart = builder.build();
post.setEntity(multipart);
// Execute the request
CloseableHttpResponse response = httpClient.execute(post);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
String responseBody = EntityUtils.toString(responseEntity);
System.out.println("Response: " + responseBody);
}
response.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import time
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# URL 和请求数据
url = "算法调用地址" # 请求的URL
request_data = {
'seq_id': 'test12021545',
'file_name': 'people_info.csv',
'file_type': 'csv'
}
files = {'file_bin': ('./people_info.csv', open('./people_info.csv', 'rb'))}
# 构建请求头
headers = {
"Content-Type": "multipart/form-data",
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
# 忽略未验证的HTTPS请求警告
warnings.filterwarnings("ignore", message="Unverified HTTPS request")
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, files=files,stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")