Merge PDF Documents API Method throws 404 error

When I try to merge PDF documents, I get the following error even though nothing in the code references Azure Storage:

error:Error calling PutMergeDocuments: {“Code”:“errorWindowsAzureStorage”,“HttpStatusCode”:404,“Description”:“Operation Failed. Windows Azure Storage Error.”,“Message”:“Windows Azure Storage exception: The remote server returned an error: (404) Not Found.”,“Data”:{},“InnerException”:null,“StackTrace”:" at Dynabic.Storage.Managers.WindowsAzureManager.RunWindowsAzureCode[T](Func1 action)\r\n at Aspose.Pdf.Cloud.Controllers.Infrastructure.FileManagerWrapper.GetDocumentStream(String path, String fileType) in C:\\ms\\src\\Aspose.PDF.Cloud\\Controllers\\Infrastructure\\FileManagerWrapper.cs:line 119\r\n at Aspose.Pdf.Cloud.Business.DocumentCreation.DocumentCreationManagerLegacy.Merge(IFileManagerWrapper fileManager, String requestRoot, IList1 files, String outputFile, HttpContext httpContext) in C:\ms\src\Aspose.PDF.Cloud\Business\DocumentCreation\DocumentCreationManagerLegacy.cs:line 129\r\n at Aspose.Pdf.Cloud.Business.PdfDocumentManager.Merge(IFileManagerWrapper fileManager, String requestRoot, IList`1 files, String outputFile, HttpContext httpContext) in C:\ms\src\Aspose.PDF.Cloud\Business\PdfDocumentManager.cs:line 294\r\n at Aspose.Pdf.Cloud.Controllers.MergeController.PutMergeDocuments(String name, MergeDocuments mergeDocuments, String storage, String folder) in C:\ms\src\Aspose.PDF.Cloud\Controllers\MergeController.cs:line 52",“HelpLink”:null,“Source”:“Dynabic.Storage”,“HResult”:-2146233088}
at Aspose.Pdf.Cloud.Sdk.Api.PdfApi.PutMergeDocumentsWithHttpInfo(String name, MergeDocuments mergeDocuments, String storage, String folder)
at Aspose.Pdf.Cloud.Sdk.Api.PdfApi.PutMergeDocuments(String name, MergeDocuments mergeDocuments, String storage, String folder)
at Aspose.Program.Main(String[] args) in /Users/paulgilchrist/Source/aspose/Program.cs:line 67

Here is the code:

            // Upload source files to aspose cloud storage
            pdfDocuments.ForEach(document => {
                // Remove file path
                document = document.Replace(convertedPath,"");
                Console.WriteLine($"PDF merge of file {document}");
                pdfApi.UploadFile(document,File.OpenRead(convertedPath + document),storage);
            });
            // Invoke Aspose.PDF Cloud SDK API to merge pdf files
            var documentResponse = pdfApi.PutMergeDocuments(outputDocumentName,mergeDocuments,storage);  //  Sometimes returns Azure Storage 404 error but why?  
            if(documentResponse != null && documentResponse.Status.Equals("OK")) {
                var bookUrl = documentResponse.Document.Links[0].Href.ToString();
                var bookStream = pdfApi.DownloadFile(bookUrl);
                using(Stream outStream = File.OpenWrite(outputPath + outputDocumentName)) {
                    bookStream.CopyTo(outStream);
                }
                Console.WriteLine("Merge Multiple PDF Files, Done!");
            }

The error occurs on the line pdfApi.PutMergeDocuments

@PGilchrist

var documentResponse = pdfApi.PutMergeDocuments(outputDocumentName,mergeDocuments,storage); // Sometimes returns Azure Storage 404 error but why?

Please double check which storage are you referring to in the code and file path/availability as well. However, if the issue persists then please share your working code along with the credentials(Client ID/Secret) in a private message.

storage=null

file/path is working fine as all the documents upload fine, and the first few merge fine. It seems to hit a merged size limit before it fails, as it is not a problem with a specific document, as I can change the order in which they are merged, causing it to error on a different file.

It looks like the issue was the mergeDocuments had the local path, and needed to be reduced just to the file name before calling PutMergeDocuments

@PGilchrist

Yes, if your referenced file is on the root of the Cloud Storage then you need to pass only file name as file path. However, if it lies in a Cloud Storage folder then you need to pass folder name as well in the file path.