Problems uploading PDF files for conversion using GroupDocs in Node.js

Description

  • I’m developing a Node.js application that allows users to upload PDF files for conversion into Word documents using the GroupDocs library. However, I’m facing a problem where the file isn’t uploaded correctly, resulting in conversion failures.

  • When I try to upload the file, I get a response indicating that the upload was unsuccessful, with the message:

{"uploaded": ["file.name"], "errors": []}

  • This suggests that the file wasn’t saved correctly, as the name returned doesn’t match the actual name of the file I’m trying to send.

Error logs:

  • The server is running on port 8080.
  • The path of the uploaded file is correct, but the upload response is not returning the expected file name.
  • The conversion fails because the file cannot be found.

Questions:

  • What could be causing this problem with the file name in the upload response?
  • How can I ensure that the file is sent correctly to the S3 and accessed at the conversion stage?

“I’d appreciate any help or suggestions to solve this problem!”

Main part of the code:

const iniciarConversao = async inputFilePath => {
    try {
        const fileStream = fs.createReadStream(inputFilePath);
        const fileApi = new groupdocs_conversion_cloud.FileApi(config);
        const uniqueFileName = `${Date.now()}_${path.basename(inputFilePath)}`;

        console.log("Tentando fazer o upload do arquivo:", uniqueFileName);

        const request = new groupdocs_conversion_cloud.UploadFileRequest(uniqueFileName, fileStream, "");
        const uploadResponse = await fileApi.uploadFile(request);

        console.log("Resposta do upload:", JSON.stringify(uploadResponse, null, 2));

        if (
            !uploadResponse ||
            !uploadResponse.uploaded ||
            uploadResponse.uploaded.length === 0 ||
            !uploadResponse.uploaded.includes(uniqueFileName)
        ) {
            console.error("Resposta de upload inválida:", uploadResponse);
            throw new Error("Falha no upload do arquivo para o S3");
        }

        const uploadedFilePath = uniqueFileName;
        console.log("Upload realizado com sucesso. Caminho após upload:", uploadedFilePath);

        const converterApi = new groupdocs_conversion_cloud.ConvertApi(config);
        const settings = new groupdocs_conversion_cloud.ConvertSettings();
        settings.filePath = uploadedFilePath;
        settings.format = "docx";
        settings.outputPath = "output";

        console.log("Configurações de conversão: ", settings);

        const convertRequest = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
        const result = await converterApi.convertDocument(convertRequest);

        console.log("Resultado bruto da conversão:", result);

        if (result && result[0].url) {
            console.log("Documento convertido com sucesso");
            return result[0].url;
        } else {
            throw new Error("Resultado da conversão está vazio ou com formato incorreto");
        }
    } catch (error) {
        console.error("Erro na conversão: ", error);
        throw error;
    }
};

My expectation is that it will work, I’m just consuming an api that already does the conversion, or at least it was supposed to do it on its own, but every time after the upload to the dashboard where I have the grupdocs account, it doesn’t do the conversion!!!