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

Free Support Forum - aspose.cloud

Compare Word Documents in PHP throws 404 error

copied the code example from https://docs.aspose.cloud/words/compare/

used our own file paths for the “request document” and “comparing with document”

tried different values with the destination filename and all return the same 404 message:

[404] Error connecting to the API (https://api.aspose.cloud/v4.0/words/online/put/compareDocument?destFileName=TestCompareDocumentOut.docx)

tried step debug through the sdk to see if we were misunderstanding a value. we may be but it’s nothing obvious if we are.

also, the PHP example is incorrect. it passes 6 arguments to a constructor that only has 5 so our code has line 16-18 as

$compareOnlineRequest = new CompareDocumentOnlineRequest(
$requestDocument, $requestCompareData, null, null, ‘TestCompareDocumentOut.docx’
);

@blueburro

It seems you are getting error due to difference in number of arguments. Please find the working sample code to compare two Word documents. You may also check sample unit tests and CompareDocumentOnlineRequest definition from GitHub for reference.

It seems the CompareDocumentOnline method is not saving output document to cloud storage as expected. We are investigating the issue(WORDSCLOUD-1748) and will update you asap. However, meanwhile, you can save the output to your local drive as follows.

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');

//TODO: Get your ClientId and ClientSecret at https://dashboard.aspose.cloud (free registration is required).

$ClientId="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx";
$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$wordsApi = new Aspose\Words\WordsApi($ClientId,$ClientSecret);


try {

	$remoteFolder = "Temp";
	$localName1 = "compareTestDoc1.doc";
    $localName2 = "compareTestDoc2.doc";
    $remoteName2 = "TestCompareDocument2.doc";
	
	$outputFileName = "TestCompareDocumentOut.doc";

        
	$uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localName2,$remoteFolder."/".$remoteName2,null);
	$wordsApi->uploadFile($uploadRequest);
	

	$requestDocument = $localName1;
    $requestCompareData = new Aspose\Words\Model\CompareData(array(
        "author" => "author",
        "comparing_with_document" => $remoteFolder . "/" . $remoteName2,
        "date_time" => new \DateTime("2015-10-26T00:00:00.0000000Z"),
    ));
    $request = new Aspose\Words\Model\Requests\CompareDocumentOnlineRequest(
        $requestDocument,
        $requestCompareData,
        NULL,
        NULL,
        NULL,
        NULL  ##$remoteFolder ."/". $outputFileName
    );

    $result = $wordsApi->compareDocumentOnline($request);
	##Save output file to local drive
	copy($result->document->getPathName(),$outputFileName);
	print_r($result->document->getPathName());
	
	##Download file from stroage
	#$downloadRequest = new Aspose\Words\Model\Requests\DownloadFileRequest($remoteFolder."/".$outputFileName,NULL,NULL);
	#$downloadResult = $wordsApi->downloadFile($downloadRequest);
	#copy($downloadResult->getPathName(),$outputFileName);
	#print_r($downloadResult);
		
		
    
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>

Ok. part of the issue is we’re locked to 21.4.0 and it looks like 21.9.0 is what the example uses.

I updated the dependency to 21.9.0 and tried the suggested code. We definitely want to get a local copy to consume.

We are NOT wanting to save to the cloud storage if possible. This should work until the issue (WORDSCLOUD-1748) you mentioned is resolved. Am I understanding correctly that resolving the WORDSCLOUD-1748 issue will allow us to NOT have to upload/store on the cloud storage?

Side note/question: Shouldn’t whatever version introduced that refactor have made the version into 22.0.0 because of backwards compatibility break?

Thank you for your help and quick reply.

@blueburro

No, if you do not want to save the output to storage then use the above shared code. So, you do not need the resolution of WORDSCLOUD-1748. And if you do not want to use the external storage at all then you may check our self-hosting Docker container solution.

I’m afraid backward compatibility will break with breaking changes. You can control it somehow with Docker Container but not completely. As we always add fixes/new features in the latest release.