Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

500
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda