Phrase TMS API

文件数据类型 (TMS)

文本由 Phrase Language AI 从英语机器翻译而得。

文件类型用于将二进制数据发布到各种 API 调用中。每个包含一个类型 ⁇ file ⁇ 的参数的 API 调用都必须符合以下要求:

  • 必须使用 HTTP POST 方法。

  • 必须形成HTML规范 ⁇ 中描述的多部分/表格数据请求。

示例

Java HttpClient

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(webServerUrl);
多部分实体请求实体 = 新的多部分实体(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(“UTF-8”));
StringBody taskPart;
StringBody formatPart;
StringBody 保存到TransMemoryPart;
StringBody setCompletedPart;
ByteArrayBody fileContentPart;
//... 用数据填充变量... //

reqEntity.addPart("task", taskPart);
reqEntity.addPart("format", formatPart);
reqEntity.addPart("saveToTransMemory", saveToTransMemoryPart);
reqEntity.addPart("setCompleted", setCompletedPart);
reqEntity.addPart("bilingualFile", fileContentPart);
httpPost.setEntity(reqEntity);

C++ Qt

QHttpMultiPart* multiPartData = new QHttpMultiPart( QHttpMultiPart::FormDataType );
QBuffer* buffer = new QBuffer( multiPartData );
buffer->open( QIODevice::WriteOnly );
//... 用数据填充缓冲区... //
writer.writeTo( buffer );
buffer->close();

QHttpPart filePart;
filePart.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/octet-stream" ) );
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name =\"双语文件\"; filename =\" ) + model->getFileInfos()[0].original + "\" ) );
buffer->open( QIODevice::ReadOnly );
filePart.setBodyDevice( buffer );
multiPartData->append( filePart );
这篇文章有帮助吗?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.