圖片轉(zhuǎn)Word
文檔介紹了圖片轉(zhuǎn)Word接口的調(diào)用方式,調(diào)用前,請先閱讀API使用指南。
圖片轉(zhuǎn)Word接口可以將圖片轉(zhuǎn)換為可編輯的Word文檔,最多同時支持30張圖片轉(zhuǎn)換,精準(zhǔn)識別文本內(nèi)容,并保留原始文檔的版面樣式信息。
圖片轉(zhuǎn)Word接口為異步接口,需要先調(diào)用圖片轉(zhuǎn)Word異步提交服務(wù)SubmitConvertImageToWordJob進(jìn)行異步任務(wù)提交,然后調(diào)用文檔轉(zhuǎn)換結(jié)果查詢服務(wù)GetDocumentConvertResult接口進(jìn)行結(jié)果輪詢,建議每10秒輪詢一次,最多輪詢120分鐘,如果120分鐘還未查詢到處理完成結(jié)果,則視為處理超時。
當(dāng)異步任務(wù)處理提交后,用戶可以在處理結(jié)束后的24小時之內(nèi)查詢處理結(jié)果,超過24小時后將無法查詢到處理結(jié)果。
步驟一:調(diào)用圖片轉(zhuǎn)Word異步提交服務(wù)SubmitConvertImageToWordJob接口
請求參數(shù)
名稱 | 類型 | 必填 | 描述 | 示例值 |
ImageUrls | List<String> | 是 | 圖片URL集合,1~30個URL(不支持8192px以上的圖片,不支持20MB以上的圖片) 如果請求URL較長導(dǎo)致請求失敗,建議減少圖片URL個數(shù)。 | ["https://example.com/example1.jpg","https://example.com/example2.jpg"] |
ImageNames | List<String> | 否 | 文件名。文件名需帶后綴名。與imageNameExtension二選一 | ["example1.jpg","example2.jpg"] |
ImageNameExtension | string | 否 | 文件后綴名。與ImageNames二選一。支持類型:jpg、jpeg、png、bmp、gif | jpg |
支持的文檔格式:30張以內(nèi)的圖片,支持jpg、jpeg、png、bmp、gif格式,其中g(shù)if格式只支持第一幀。不支持最長邊在8192px以上的圖片,不支持20MB以上的圖片。
返回參數(shù)
名稱 | 類型 | 描述 | 示例值 |
RequestId | string | 請求唯一ID | 43A29C77-405E-4CC0-BC55-EE694AD0**** |
Data | object | 返回數(shù)據(jù) | {"Id": "docmind-20220712-b15f****"} |
+Id | string | 業(yè)務(wù)訂單號,用于后續(xù)查詢接口進(jìn)行查詢的唯一標(biāo)識 | docmind-20220712-b15f**** |
Code | string | 狀態(tài)碼 | 200 |
Message | string | 詳細(xì)信息 | message |
示例
本接口支持傳入文檔URL的調(diào)用方式,不支持本地文檔上傳。
以Java SDK為例,傳入文檔URL調(diào)用方式的請求示例代碼如下,調(diào)用submitConvertImageToPdfJob接口,通過imageUrls參數(shù)實現(xiàn)多個文檔URL傳入。請注意,您傳入的文檔URL必須為公網(wǎng)可訪問下載的公網(wǎng)URL地址,無跨域限制,URL不帶特殊轉(zhuǎn)義字符。
獲取并使用AccessKey信息的方式,可參考SDK概述中不同語言的SDK使用指南。
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void submit() throws Exception {
// 使用默認(rèn)憑證初始化Credentials Client。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// 通過credentials獲取配置中的AccessKey ID
.setAccessKeyId(credentialClient.getAccessKeyId())
// 通過credentials獲取配置中的AccessKey Secret
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
SubmitConvertImageToWordJobRequest imageToWordJobRequest = new SubmitConvertImageToWordJobRequest();
String fileUrl1 = "https://example.com/example1.jpg";
String fileUrl2 = "https://example.com/example2.jpg";
imageToWordJobRequest.imageUrls = Arrays.asList(fileUrl1, fileUrl2);
// 填寫第一張圖片的文件擴(kuò)展名
imageToWordJobRequest.imageNameExtension = "jpg";
SubmitConvertImageToWordJobResponse response = client.submitConvertImageToWordJob(imageToWordJobRequest);
}}
const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// 使用默認(rèn)憑證初始化Credentials Client
const cred = new Credential.default();
const client = new Client.default({
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// 通過credentials獲取配置中的AccessKey ID
accessKeyId: cred.credential.accessKeyId,
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const request = new Client.SubmitConvertImageToWordJobRequest();
request.imageUrls = [
'https://example.com/example1.jpg',
'https://example.com/example2.jpg'
];
request.imageNameExtension = 'jpg';
const response = await client.submitConvertImageToWordJob(request);
return response.body;
}
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
def submit_url():
cred=CredClient()
config = open_api_models.Config(
# 通過credentials獲取配置中的AccessKey ID
access_key_id=cred.get_access_key_id(),
# 通過credentials獲取配置中的AccessKey Secret
access_key_secret=cred.get_access_key_secret()
)
# 訪問的域名
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.SubmitConvertImageToWordJobRequest(
# image_urls : 圖片url地址
image_urls=['https://example.com/example.jpg'],
# image_name_extension :圖片格式。與圖片名二選一
image_name_extension='jpg',
# image_names :圖片名稱。名稱必須圖片類型
image_names=['123.jpg'],
)
try:
# 復(fù)制代碼運(yùn)行請自行打印 API 的返回值
response = client.submit_convert_image_to_word_job(request)
# API返回值格式層級為 body -> data -> 具體屬性??筛鶕?jù)業(yè)務(wù)需要打印相應(yīng)的結(jié)果。如下示例為打印返回的業(yè)務(wù)id格式
# 獲取屬性值均以小寫開頭,
print(response.body.data.id)
except Exception as error:
# 如有需要,請打印 error
UtilClient.assert_as_string(error.message)
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void SubmitUrl()
{
// 使用默認(rèn)憑證初始化Credentials Client。
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 通過credentials獲取配置中的AccessKey Secret
AccessKeyId = akCredential.GetAccessKeyId(),
// 通過credentials獲取配置中的AccessKey Secret
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// 訪問的域名
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
List<string> list = new List<string>();
list.Add("https://example.com/example1.jpg");
list.Add("https://example.com/example2.jpg");
AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitConvertImageToWordJobRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitConvertImageToWordJobRequest
{
ImageUrls = list,
ImageNameExtension = "jpg"
};
try
{
// 復(fù)制代碼運(yùn)行請自行打印 API 的返回值
client.SubmitConvertImageToWordJob(request);
}
catch (TeaException error)
{
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}
import (
"fmt"
openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit() {
// 使用默認(rèn)憑證初始化Credentials Client。
credential, err := credentials.NewCredential(nil)
// 通過credentials獲取配置中的AccessKey ID
accessKeyId, err := credential.GetAccessKeyId()
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret, err := credential.GetAccessKeySecret()
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// 初始化client
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
fileUrl1 := "https://example.com/example1.jpg"
fileUrl2 := "https://example.com/example2.jpg"
imageExtension := "jpg"
request := client.SubmitConvertImageToWordJobRequest{
ImageUrls: []*string{&fileUrl1, &fileUrl2},
ImageNameExtension: &imageExtension,
}
response, err := cli.SubmitConvertImageToWordJob(&request)
if err != nil {
panic(err)
}
fmt.Println(response.Body)
}
use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\SubmitConvertImageToWordJobRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// 使用默認(rèn)憑證初始化Credentials Client。
$bearerToken = new Credential();
$config = new Config();
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// 通過credentials獲取配置中的AccessKey ID
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// 通過credentials獲取配置中的AccessKey Secret
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new SubmitConvertImageToWordJobRequest();
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
$request->imageUrls = array(
"https://example.com/example1.jpg",
"https://example.com/example2.jpg"
);
$request->imageNameExtension = "jpg";
try {
$response = $client->submitConvertImageToWordJob($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}
正常返回示例
JSON
格式
{
"RequestId": "43A29C77-405E-4CC0-BC55-EE694AD0****",
"Data": {
"Id": "docmind-20220712-b15f****"
}
}
步驟二:輪詢文檔轉(zhuǎn)換結(jié)果查詢服務(wù)GetDocumentConvertResult接口
調(diào)用查詢接口的入?yún)d就是前面異步任務(wù)提交接口返回的出參ID,查詢結(jié)果有處理中、處理成功、處理失敗三種情況。建議每10秒輪詢一次,最多輪詢120分鐘。若明確返回Completed為true或者超過輪詢最大時間,則終止輪詢。
請求參數(shù)
名稱 | 類型 | 必填 | 描述 | 示例值 |
Id | string | 是 | 需要查詢的業(yè)務(wù)訂單號,訂單號從提交接口的返回結(jié)果中獲取 | docmind-20220712-b15f**** |
返回參數(shù)
名稱 | 類型 | 描述 | 示例值 |
RequestId | string | 請求唯一ID | 43A29C77-405E-4CC0-BC55-EE694AD0**** |
Completed | boolean | 異步任務(wù)是否處理完成,false表示任務(wù)仍在處理中,true代表任務(wù)處理完成,有處理成功或處理失敗的明確結(jié)果 | true |
Status | string | 異步任務(wù)處理完成的狀態(tài),最終處理結(jié)束后的狀態(tài)。Success為處理成功,F(xiàn)ail為處理失敗 | Success |
Data | object | 文檔轉(zhuǎn)換的結(jié)果,具體參數(shù)詳情見下表 | 是個列表 |
Code | string | 狀態(tài)碼 | 200 |
Message | string | 詳細(xì)信息 | message |
+Url | String | 轉(zhuǎn)換后的文件URL地址 | https://example.com/example.docx |
+Size | Integer | 轉(zhuǎn)換后的文件大小,單位為字節(jié)。 | 1345488 |
+Type | String | 轉(zhuǎn)換后的文件后綴名 | docx |
+Md5 | String | 轉(zhuǎn)換后的文件md5值,調(diào)用者可以用于校驗 | 2d49eb7705f9f93ed857874db247**** |
以Java SDK為例,調(diào)用文檔智能解析接口的結(jié)果查詢類API示例代碼如下,調(diào)用getDocumentConvertResult接口,通過id參數(shù)傳入查詢流水號。
獲取并使用AccessKey信息的方式,可參考SDK概述中不同語言的SDK使用指南。
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void submit() throws Exception {
// 使用默認(rèn)憑證初始化Credentials Client。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// 通過credentials獲取配置中的AccessKey ID
.setAccessKeyId(credentialClient.getAccessKeyId())
// 通過credentials獲取配置中的AccessKey Secret
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
GetDocumentConvertResultRequest resultRequest = new GetDocumentConvertResultRequest();
resultRequest.id = "docmind-20220902-824b****";
GetDocumentConvertResultResponse response = client.getDocumentConvertResult(resultRequest);
}
const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// 使用默認(rèn)憑證初始化Credentials Client
const cred = new Credential.default();
const client = new Client.default({
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// 通過credentials獲取配置中的AccessKey ID
accessKeyId: cred.credential.accessKeyId,
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const resultRequest = new Client.GetDocumentConvertResultRequest();
resultRequest.id = "docmind-20220902-824b****";
const response = await client.getDocumentConvertResult(resultRequest);
return response.body;
}
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
def query():
cred=CredClient()
config = open_api_models.Config(
# 通過credentials獲取配置中的AccessKey ID
access_key_id=cred.get_access_key_id(),
# 通過credentials獲取配置中的AccessKey Secret
access_key_secret=cred.get_access_key_secret()
)
# 訪問的域名
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.GetDocumentConvertResultRequest(
# id : 任務(wù)提交接口返回的id
id='docmind-20220902-824b****'
)
try:
# 復(fù)制代碼運(yùn)行請自行打印 API 的返回值
response = client.get_document_convert_result(request)
# API返回值格式層級為 body -> data -> 具體屬性??筛鶕?jù)業(yè)務(wù)需要打印相應(yīng)的結(jié)果。獲取屬性值均以小寫開頭
# 獲取異步任務(wù)處理情況,可根據(jù)response.body.completed判斷是否需要繼續(xù)輪詢結(jié)果
print(response.body.completed)
# 獲取返回結(jié)果。建議先把response.body.data轉(zhuǎn)成json,然后再從json里面取具體需要的值。
print(response.body.data)
except Exception as error:
# 如有需要,請打印 error
UtilClient.assert_as_string(error.message)
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void GetResult()
{
// 使用默認(rèn)憑證初始化Credentials Client。
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 通過credentials獲取配置中的AccessKey Secret
AccessKeyId = akCredential.GetAccessKeyId(),
// 通過credentials獲取配置中的AccessKey Secret
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// 訪問的域名
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocumentConvertResultRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocumentConvertResultRequest
{
Id = "docmind-20220902-824b****"
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
// 復(fù)制代碼運(yùn)行請自行打印 API 的返回值
client.GetDocumentConvertResult(request);
}
catch (TeaException error)
{
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}
import (
"fmt"
"os"
openClient "github.com/alibabacloud-go/darabonba-openapi/client"
"github.com/alibabacloud-go/docmind-api-20220711/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit(){
// 使用默認(rèn)憑證初始化Credentials Client。
credential, err := credentials.NewCredential(nil)
// 通過credentials獲取配置中的AccessKey ID
accessKeyId, err := credential.GetAccessKeyId()
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret, err := credential.GetAccessKeySecret()
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// 初始化client
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
id := "docmind-20220925-76b1****"
// 調(diào)用查詢接口
request := client.GetDocumentConvertResultRequest{Id: &id}
response, err := cli.GetDocumentConvertResult(&request)
if err != nil {
panic(err)
}
// 打印查詢結(jié)果
fmt.Println(response.Body)
//注意,使用go語言sdk會將返回結(jié)果中Url中的特殊字符&做Unicode轉(zhuǎn)碼,轉(zhuǎn)碼成\u0026,需要調(diào)用者手動將\u0026進(jìn)行Unicode轉(zhuǎn)碼回&,才可以正常下載URL
//go語言sdk的Url返回示例如下http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/convert/docmind-20220927-87ad**/example.pdf?Expires=XX\u0026OSSAccessKeyId=YY\u0026Signature=ZZ
}
use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\GetDocumentConvertResultRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// 使用默認(rèn)憑證初始化Credentials Client。
$bearerToken = new Credential();
$config = new Config();
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// 通過credentials獲取配置中的AccessKey ID
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// 通過credentials獲取配置中的AccessKey Secret
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new GetDocumentConvertResultRequest();
$request->id = "docmind-20220902-824b****";
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
try {
$response = $client->getDocumentConvertResult($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}
查詢結(jié)果有處理中、處理成功、處理失敗三種情況,分別說明每種情況的返回結(jié)果示例。
處理中的返回結(jié)果如下所示:
{
"RequestId": "2AABD2C2-D24F-12F7-875D-683A27C3****",
"Completed": false,
"Code": "DocProcessing",
"Message": "Document processing",
"HostId": "ocr-api.cn-hangzhou.aliyuncs.com",
"Recommend": "https://next.api.aliyun.com/troubleshoot?q=DocProcessing&product=docmind-api"
}
處理中Completed會返回false,表示任務(wù)沒有處理結(jié)束,仍在處理中。這種情況需要繼續(xù)輪詢,直到明確返回Completed為true或者超過輪詢最大時間。
處理失敗的返回結(jié)果如下所示:
{
"RequestId": "A8EF3A36-1380-1116-A39E-B377BE27****",
"Completed": true,
"Status": "Fail",
"Code": "UrlNotLegal",
"Message": "Failed to process the document. The document url you provided is not legal.",
"HostId": "docmind-api.cn-hangzhou.aliyuncs.com",
"Recommend": "https://next.api.aliyun.com/troubleshoot?q=IDP.UrlNotLegal&product=docmind-api"
}
處理失敗Completed會返回true,表示任務(wù)處理結(jié)束,同時會返回Status為字符串的Fail,表示處理成功失敗,同時會返回失敗Code和詳細(xì)原因Message。訪問錯誤碼可以查看錯誤碼詳細(xì)介紹。
處理成功的返回結(jié)果如下所示:
{
"Status": "Success",
"RequestId": "73134E1A-E281-1B2C-A105-D0ECFE2D****",
"Completed": true,
"Data": [
{
"Type": "docx",
"Size": 7940,
"Url": "http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/convert/docmind-20220902-57de****/example.docx?Expires=1662190830&OSSAccessKeyId=XX&Signature=YY",
"Md5": "36256a4c2db8e31e056aeeb8b871****"
}
]
}
處理成功Completed會返回true,表示任務(wù)處理結(jié)束,同時會返回Status為字符串的Success,表示處理成功。具體的處理結(jié)果在Data節(jié)點中,接下來介紹下Data節(jié)點的具體格式:
Type表示轉(zhuǎn)換后文檔的文檔類型,例如該圖片轉(zhuǎn)word接口返回的是docx格式的word文檔。
Url表示轉(zhuǎn)換后文檔的下載鏈接,每次查詢請求返回的Url下載鏈接的有效期為60分鐘,超期后該Url會失效,需要重新調(diào)用查詢接口拿到新的Url下載鏈接。
Size表示轉(zhuǎn)換后文檔的文件大小,單位是字節(jié),可以用于對用戶下載的轉(zhuǎn)換后文檔做合法性校驗,比較下載的轉(zhuǎn)換后文檔的文件大小和接口返回的Size是否相等。
Md5表示轉(zhuǎn)換后文檔的文件Md5摘要值,可以用于對用戶下載的轉(zhuǎn)換后文檔做合法性校驗,比較下載的轉(zhuǎn)換后文檔的Md5摘要值和接口返回的Md5是否相等。