I am getting request timeout error even for 6kb image while uploading on cloudinary . Here is my cod

Options
Rimjhim_Jain
Rimjhim_Jain Member Posts: 3

multer.js

import DatauriParser from 'datauri/parser.js';

import path from 'path';


const storage = multer.memoryStorage();

const multerUploads = multer({ storage }).single("file");


const dUri = new DatauriParser();

const dataUri = req => dUri.format(path.extname(req.file.originalname).toString(), req.file.buffer);


export {multerUploads,dataUri};



server.js

import app from "./app.js";

import { multerUploads, dataUri } from './multer.js';

import cloudinary from 'cloudinary';


cloudinary.v2.config({

        cloud_name: process.env.CLOUDINARY_CLIENT_NAME,

        api_key: process.env.CLOUDINARY_CLIENT_API,

        api_secret: process.env.CLOUDINARY_CLIENT_SECRET,

        secure: true,

    });


app.post('/upload', multerUploads, (req, res) => {

    if (req.file) {

        const file = dataUri(req).content;

        //console.log(file);

        return cloudinary.v2.uploader.upload(file).then((result) => {

            const image = result.url;

            return res.status(200).json({

                message: 'Your image has been uploded successfully to cloudinary',

                data: {

                    image

                }

            })

        }).catch((err) => res.status(400).json({

            message: 'someting went wrong while processing your request',

            data: {

                err

            }

        }))

    }

});


app.listen(process.env.PORT,()=>{

    console.log(`Server is working on port: ${process.env.PORT}`);


})

Answers

  • epasos
    epasos Member, Cloudinary Staff Posts: 23
    Options

    @Rimjhim_Jain Kindly ensure that the cloudinary config parameters can be loaded from the .env file. You may check out this documentation for additional information on uploading to your Cloudinary account using Multer. Please take a look and let us know of any further issues. Thanks,

  • Rimjhim_Jain
    Rimjhim_Jain Member Posts: 3
    Options

    I have directly use the parameters then also it is giving the same error.

    { message: 'Request Timeout', http_code: 499, name: 'TimeoutError' }

  • Rimjhim_Jain
    Rimjhim_Jain Member Posts: 3
    Options

    I got the solution, just use another wifi network.

  • johnr
    johnr Member Posts: 7
    Options

    Great to know that you solved it already @Rimjhim_Jain!