We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

Comparing two .doc documents results in corrupt comparison file

I’ve been trying to compare two .doc documents using the /words/online/put/compareDocument api endpoint. The api responds with a 200 OK status code yet the response body contains chaotic content which I’m unable to convert to a .doc document. The response Content-Type is ‘multipart/mixed; boundary="…"’. You can see the response body in the image (99.9 KB).

I’m using typescript to send requests to the api (I write the requests myself, without the library, due to some conflicts that the library causes). Is that response correct? If so how do I convert that response into a .doc document? If not why do I get it and how does a request to that endpoint look like when only using typescript features (How do I get a correct response file which I can work with?)?

Thanks for a response in advance


Thanks for your inquiry. We are looking into your requirements and will guide you shortly.


Yes, the response is correct. As the API response is multipart, you need to parse it to get the resultant document. For example, please check the sample Node.js code to compare two word documents from the local drive. It will give you an idea of how to resolve your issue.

const { WordsApi, CompareData, CompareDocumentOnlineRequest } = require("asposewordscloud");
var fs = require('fs');

const compare = async () => {
// Get Client ID and Secret from https://dashboard.aspose.cloud/
wordsApi = new WordsApi("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxx");

try {

const requestDocument = fs.createReadStream("compareTestDoc1.doc");
const requestCompareData = new CompareData({
    author: "author"
const requestComparingDocument = fs.createReadStream("compareTestDoc2.doc");
const compareRequest = new CompareDocumentOnlineRequest({
    document: requestDocument,
    compareData: requestCompareData,
    comparingDocument: requestComparingDocument
    //destFileName: "CompareDocumentOut.doc"

.then((compareRequestResult) => {
    // tslint:disable-next-line:no-console
 const compareOutputDocument =compareRequestResult.body.document.entries().next().value[1];
 fs.writeFileSync("CompareDocumentOut.doc", compareOutputDocument);
} catch (err) {
throw err;

.then(() => {
console.log("documents compared.... successfully");
.catch((err) => {
console.log("Error occurred while comparing the documents:", err);

Furthermore, please note that the Aspose.Words Cloud SDK for Node.js has .ts files; you can use the SDK with typescript. However, if you are having some issues using it, then please share some details of the issues. We will look into these and help you use the SDK.

Thanks for your fast response @tilal.ahmad . Before opening this question, I’ve already been trying to parse this multipart response (unsuccessfully). Additionally I am unable to resolve my issue using the code in your response :frowning: .

So how can I parse the response without using the asposewordscloud library (preferably without using any library)?

And on top of that: why does it say the following inside the response?

“FileName”: “testDest.doc”,
“SourceFormat”: “Docx”,

Why is the SourceFormat Docx if I’m downloading a .doc document? Is that supposed to be like that?


I am afraid I am not good at typescript. You can google how to parse JSON using typescript. I think it will help you accomplish the task.

The default SourceFormat value is Docx. If you want to compare PDF documents, then you need to set it to PDF.

I know how to parse json, but the response I’m getting is not json. It’s multipart/mixed content in which the first part is json, tho not relevant to me. The second part is what matters to me as it contains the file. But if I remove everything except the binary data (which I suppose is the file) and convert it into a .doc document, when opening the file, word tells me that the file has been corrupted (irrepairable). Now why is that the case and how do I fix that? How do I get a usable file?


Please share your working sample code with us. We will try to replicate the issue and investigate it.

In the following you can see the current code. accessToken is the access token generated by the https://api.aspose.cloud/connect/token endpoint (and is correct for sure). this.file1.file and this.file2.file are files of type File. The output variable stores my attempt of parsing the response. And as I said: The resulting file is a corrupted msword document.

const ASPOSE_BASE_URL = "https://api.aspose.cloud/v4.0";

let httpReq = new XMLHttpRequest();
let requestData = new FormData();

httpReq.open("PUT", `${ASPOSE_BASE_URL}/words/online/put/compareDocument?destFileName=testDest.doc`, false);
httpReq.setRequestHeader("Authorization", "Bearer " + accessToken);

requestData.append("Document", this.file1.file);
requestData.append("CompareData", JSON.stringify({
    "Author": "author",
    "ComparingWithDocument": this.file2.file.name,
    "DateTime": "2015-10-26T00:00:00Z"
requestData.append("ComparingDocument", this.file2.file);

httpReq.onload = () => {
    const contentType = httpReq.getResponseHeader("Content-Type");
    const boundary = contentType.split(";")[1].trim().split("=")[1].slice(1, -1);

    let output = httpReq.responseText.split(boundary)[2];
    output = output.slice(output.indexOf("\n")+1, -4);
    output = output.slice(output.indexOf("\n")+1);
    output = output.slice(output.indexOf("\n")+1);

    let file = new Blob([output], {type: "application/msword"});
    const downloadLink = document.createElement("a");
    downloadLink.target = "_self";
    const datas = window.URL.createObjectURL(file);
    downloadLink.href = datas;
    downloadLink.download = "testDest";


Thanks for sharing the sample code. We have logged a ticket(WORDSCLOUD-2409) to investigate the problem and will keep you updated about the issue resolution progress within this forum thread.


Thanks a lot. Looking forward to hearing from you.

1 Like


Certainly, once we make some significant progress towards issue resolution, we will keep you informed.

1 Like


Within what time frame can I expect the issue to be resolved?


We have planned the issue’s investigation for this week and will share our findings with you accordingly.


Hey, is there an update on the issue?


I am afraid the issue is still not resolved. I have asked for an update and will share it with you as soon as possible.


We might have an idea of why the issue occurs: The response we get when sending the request without the library is encoded with utf-8, yet when sending the request with the library, the response is encoded with ANSI. We tried to set the loadEncoding parameter to ansi, yet that yields an error response (500, message="‘ansi’ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter ‘name’)".

How do we change the encoding such that we get back ansi, which we may be able to process?


Thanks for sharing your findings. We are already working on the solution without Aspose.Words Cloud SDKs but using a rest client and we will share the sample code with you shortly.