1

I am trying to insert file which is formatted as Base64 using insertFileFromBase64() but I am getting this exception:

{
    "name": "OfficeExtension.Error",
    "code": "GeneralException",
    "message": "ooxmlIsMalformated",
    "traceMessages": [],
    "innerError": null,
    "debugInfo": {
        "code": "GeneralException",
        "message": "ooxmlIsMalformated",
        "errorLocation": "Body.insertFileFromBase64"
    }
}

My code is:

// documentData - is a base64 string.
// Encoded base64 string = "V29yZCBEb2N1bWVudCBpcyBub3QgZ2V0IGluc2VydGVkIHVzaW5nIGluc2VydEZpbGVCYXNlNjQ="
body.insertFileFromBase64(documentData,window.Word.InsertLocation.replace);

I have tried other methods for HTML and text that are working, but getting the exception with insertFileFromBase64.

Can someone please guide me if I am missing anything here?

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Chandan
  • 175
  • 1
  • 2
  • 7

1 Answers1

0

From the documentation, the base64File parameter takes "The base64 encoded content of a .docx file."

The string your passing isn't an encoded .docx, it is simply an encoded string. The exception your getting is correct, the OOXML you are passing is malformated (or more precisely, it isn't OOXML at all).

You will need to pass in a proper OOXML document that has been Base64 encoded for this method to work.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • Thanks, @Marc LaFleur, Is there any way to convert OOMXL document into Base64 in Office js? I tried to convert OOXML to base64 using javascript but yet no luck... – Chandan Nov 17 '17 at 08:08
  • Base64 is just an encoding. You would encode it just as you would any other file type. This might help https://stackoverflow.com/questions/36280818/how-to-convert-file-to-base64-in-javascript – Marc LaFleur Nov 17 '17 at 13:58