Socket Hang up Nodejs CompressPDF

New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

[0] [nodemon] starting `node server index.js`
[0] No logging configuration. Using default config
[0] Server started on port 5000
[0] 2021-10-14T10:38:10.175:[INFO]: All validations successfully done. Beginning Compress PDF operation execution
[0] Exception encountered while executing operation ServiceApiError: request timed out, 6000 seconds expired
[0]     at ClientRequest.<anonymous> (C:\Users\thoma\WebstormProjects\pdf_react\node_modules\@adobe\pdfservices-node-sdk\src\internal\http\http-client.js:276:13)
[0]     at ClientRequest.emit (events.js:400:28)
[0]     at TLSSocket.emitRequestTimeout (_http_client.js:790:9)
[0]     at Object.onceWrapper (events.js:519:28)
[0]     at TLSSocket.emit (events.js:412:35)
[0]     at TLSSocket.Socket._onTimeout (net.js:484:8)
[0]     at listOnTimeout (internal/timers.js:557:17)
[0]     at processTimers (internal/timers.js:500:7) {
[0]   requestTrackingId: undefined,
[0]   statusCode: 0,
[0]   errorCode: 'UNKNOWN'
[0] }
[0] 2021-10-14T10:38:20.531:[ERROR]: Unexpected Error, request could not be completed Error: socket hang up

 

 

I upped the timout to 600000 and it is still saying it is hanging up within about 20 seconds, here is my node js code.

app.post('/api/pdf-upload', async (req, res) => {
    try {
        // Initial setup, create credentials instance.
        const credentials =  PDFServicesSdk.Credentials
            .serviceAccountCredentialsBuilder()
            .fromFile("pdfservices-api-credentials.json")
            .build();
        // Create client config instance with custom time-outs.
        const clientConfig = PDFServicesSdk.ClientConfig
            .clientConfigBuilder()
            .withConnectTimeout(6000000)
            .build();
        fs.ensureDir(`./uploads/`, async (err) => {
            await req.files.filepond.mv(__dirname + '/uploads/' + req.files.filepond.name, (err) => {
                if (err) {
                    console.log(err)
                }
                // Create an ExecutionContext using credentials and create a new operation instance.
                const executionContext =  PDFServicesSdk.ExecutionContext.create(credentials, clientConfig),
                    compressPDF =  PDFServicesSdk.CompressPDF,
                    compressPDFOperation =  compressPDF.Operation.createNew();
                const input = PDFServicesSdk.FileRef.createFromLocalFile(`uploads/${req.files.filepond.name}`);
                    compressPDFOperation.setInput(input);

                compressPDFOperation.execute(executionContext)
                    .then(result => result.saveAsFile(`uploads/compress${req.files.filepond.name}`))
                    .catch(err => {
                        if(err instanceof PDFServicesSdk.Error.ServiceApiError
                            || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
                            console.log('Exception encountered while executing operation', err);
                        } else {
                            console.log('Exception encountered while executing operation', err);
                        }
                    });
                return res.status(200)

            })


        })

    } catch (err) {
        console.log(err)
    }

})

Views

416

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Is there a maximum file size?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

LATEST

Hi, Please check this discussion, looks like same error. I tried and it helped me, though I used for PDF Extract.

https://community.adobe.com/t5/document-services-apis-discussions/document-services-api-node-js-sock... 

// http: {
// 	connectTimeout:10000,
// 	readTimeout: 10000
// },

// change like this 

http: {
	connectTimeout: 20000,
	readTimeout: 20000
},

in node_modules/@adobe/pdfservices-node-sdk\src/internal/config/dc-services-default-config.js 41

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines