Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

499
Views
How can I convert a .docx file from a server with mammoth?

I have just installed mammoth.browser.min (v. 1.2.0) and, using an HTML tag as shown in the docs, tested it successfully on .docx files to be displayed in the browser.

Then I tried to implement parseWordDocxFile through a different interface: after loading files onto a server using $.post, I display them as a list. From this list, any line can be double-clicked like so:

let myFile = {"reference": reference, "type": type};
openDocument (myFile);

" reference " and "type" are retrieved from a $.get request: "reference" is the full path to the intended file; "type" is the file type.

The signature of the callee is openDocument (theFile). This function includes a switch:

switch (theFile.type)
{
       case 'pdf': case 'PDF': case 'PNG': case 'png': case 'JPEG': case 'jpg': case 'JPG':
         window.open ( file.reference ); // browser handles it directly
      break;               
      case 'docx': parseWordDocxFile(file.reference);  break; // full path to the file, checked
}

For file types .pdf, .png, .jpg, is works smoothly.

Now, as to .docx files, it avails to nothing. Upon entering parseWordDocxFile, Debugger says:

TypeError: FileReader.readAsArrayBuffer: Argument 1 is not an object

BUT if I copy back the file from the server onto my local disk and try and open it with the HTML interface (ditto), it works. In other words there is nothing wrong with the file stored on the server.

I surmise that I might pass parseWordDocxFile(theFile) an file object like so:

var objFile = new File ( [data], // type:= []
                            "Sample.docx", // full path correct
                            {
                                type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // type displayed on debugging
                                lastModified: 1650875824000
                            }

but I have no clue as to what data would be.

What is it I am doing wrong? What is the right way to get it working?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!