Error on inserting Base64 word content into WOPI word

Faizan Mohammed 0 Reputation points
2026-09-17T12:42:09.5933333+00:00

My goal is to first save the Word document using the getFileAsync() method, which is currently working as expected. The Word file is successfully retrieved and saved to the cloud server.

The issue occurs when I retrieve the saved file through an API call and attempt to insert it back into the Word document using the insertFileFromBase64() method. The first insertion works correctly, and the file is inserted into the document as expected. However, when I attempt to insert the same file again, the operation either does nothing or fails with an OOXML malformed error.

In summary, the file is being saved correctly on the server, and the first insertFileFromBase64() operation works as expected. The problem occurs during subsequent attempts to insert the file into the document, where the method either fails silently or returns an OOXML malformed error.

I have attached the taskpanetaskpane.txt file for reference. I would like to understand why the first insertion succeeds but subsequent insertions fail, and whether there is an issue with the document state, Base64 content, OOXML structure, or the way insertFileFromBase64() is being called.taskpane.txt

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments

2 answers

Sort by: Most helpful
  1. Faizan Mohammed 0 Reputation points
    2026-09-18T10:19:39.9966667+00:00

    Please find the answers below for the queries:

    1. Base64 comparison
      • Is the exact same Base64 string returned by your API used for both the first and subsequent insertFileFromBase64() calls?
      • Yes, exact same base65 string is returned by API.
      • Could you please log the Base64 string length (rather than the full content) immediately before each call and confirm whether the length/content is identical?
      • I have confirmed it and it is valid length. I cross checked the string by pasting it to base64 to word converter online and it is getting converted to word file perfectly.
    2. How the file is obtained
      • Please confirm whether the file retrieved from the server is the original output from getFileAsync(), or whether it is decoded, converted, compressed, or otherwise processed before being returned by the API.
      • Yes, the file is same as saved from getFileAsync(). There is no processing on it. The file is sent in slices the to the server and when last slice is sent, it then merges all those slices and makes a word document file.
      • If possible, please provide the relevant API response format or a sanitized sample.
      • I have attached the returned base64 content from API. base64 content.txt
    3. Insertion code - please refer these methods: insertUsingBase64() - for inserting the base64 into the word file and sendFile() - for how file slices are sent to server.
      • Please share the smallest code sample containing:
      • getFileAsync()
      • the API call used to retrieve the saved file
      • the Base64 conversion
      • both insertFileFromBase64() calls
      • Please also include the coercionType and insertLocation values used.
    4. Document state
      • Are the two insertions performed in the same Word document/session?
      • Yes.
      • Are they performed sequentially, with context.sync() completed after the first insertion?
      • Yes.
      • Does the second insertion fail only when inserting the same file twice, or does it also fail when inserting a different valid .docx file?
      • Second inserting is behaving very randomly. After 15 to 60 seconds, it will get inserted out of nowhere when I am working on the document.
    5. Error details - please check the attached image file for errors. Errors screenshot.png
      • For the "OOXML malformed" error, please provide the complete error message and error code, if available.
      • If the operation fails silently, please confirm whether the returned Word.run()/Promise is resolving successfully or whether an exception is being caught elsewhere.

    Was this answer helpful?

    0 comments No comments

  2. BabybooHN 3,125 Reputation points Independent Advisor
    2026-09-17T13:49:18.55+00:00

    Dear @Faizan Mohammed

    Thank you for the detailed explanation. Since the first insertFileFromBase64() succeeds, I would like to narrow down whether the issue is related to the Base64 content itself or to the document state after the first insertion.

    Could you please provide the following details?

    1. Base64 comparison
      • Is the exact same Base64 string returned by your API used for both the first and subsequent insertFileFromBase64() calls?
      • Could you please log the Base64 string length (rather than the full content) immediately before each call and confirm whether the length/content is identical?
    2. How the file is obtained
      • Please confirm whether the file retrieved from the server is the original output from getFileAsync(), or whether it is decoded, converted, compressed, or otherwise processed before being returned by the API.
      • If possible, please provide the relevant API response format or a sanitized sample.
    3. Insertion code
      • Please share the smallest code sample containing:
      • getFileAsync()
      • the API call used to retrieve the saved file
      • the Base64 conversion
      • both insertFileFromBase64() calls
      • Please also include the coercionType and insertLocation values used.
    4. Document state
      • Are the two insertions performed in the same Word document/session?
      • Are they performed sequentially, with context.sync() completed after the first insertion?
      • Does the second insertion fail only when inserting the same file twice, or does it also fail when inserting a different valid .docx file?
    5. Error details
      • For the "OOXML malformed" error, please provide the complete error message and error code, if available.
      • If the operation fails silently, please confirm whether the returned Word.run()/Promise is resolving successfully or whether an exception is being caught elsewhere.

    As an additional test, could you please try inserting the same Base64 content twice using a freshly opened blank Word document? This will help determine whether the issue is specific to the document’s state after the first insertion.

    I have not yet concluded that the saved Base64/OOXML is corrupted. The fact that the first insertion succeeds makes it important to compare the exact payload and execution state between the first and second calls.

    Once I have the above information and the relevant taskpane.txt code, I can help identify whether the problem is with the Base64 conversion, OOXML package, insertion location, or the Office.js document state.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.