Memsource REST API

File Data Type

A file's data type is used to post binary data into various API calls. Every API call that contains at least one argument of type file has to meet the following requirements:

  • HTTP POST method must be used.

  • Multipart/form-data request as described in HTML specs must be formed.


Java HttpClient

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(webServerUrl);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
StringBody taskPart;
StringBody formatPart;
StringBody saveToTransMemoryPart;
StringBody setCompletedPart;
ByteArrayBody fileContentPart;
// ... fill variables with data ... //

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

C++ Qt

QHttpMultiPart* multiPartData = new QHttpMultiPart( QHttpMultiPart::FormDataType );
QBuffer* buffer = new QBuffer( multiPartData );
buffer->open( QIODevice::WriteOnly );
// ... fill buffer with data ... //
writer.writeTo( buffer );

QHttpPart filePart;
filePart.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/octet-stream" ) );
filePart.setHeader( QNetworkRequest::ContentDispositionHeader, QVariant( QString( "form-data; name=\"bilingualFile\"; filename=\"" ) + model->getFileInfos()[0].original + "\"" ) );
buffer->open( QIODevice::ReadOnly );
filePart.setBodyDevice( buffer );
multiPartData->append( filePart );
Was this article helpful?

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.