503 error when posting file to php server using formdata module using Node js and axios
P粉502608799
P粉502608799 2024-02-26 15:45:04
0
1
366

I'm trying to send a file from my Node js application to a PHP server hosting an opencart application. I'm using formdata and axios modules to make requests and upload files.

My problem is that I get this error Error: Request failed with status code 503

How to solve?

This is my code in Node.js:

let form = new FormData();
form.append("file", fs.createReadStream(path.resolve(zipFilePath)), path.basename(zipFilePath));

            try {
                let response = await axios.post(endpoint, form, {
                    headers: {
                        ...form.getHeaders(),
                    },
                });

                const result = response.data;
                if (result && result.status === "success") {
                    fs.unlinkSync(zipFilePath);
                }
            } catch (e) {
                console.log(e.toString());
            }

and php code (function in controller):

public function upload() {
        header('Access-Control-Allow-Origin: *');
        
        if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
            $this->response->setOutput(json_encode([]));
        } else {
            // process the file posted
        }
    }

P粉502608799
P粉502608799

reply all(1)
P粉436052364

problem solved.

The problem is that the opencart application is set to maintenance mode on the backend, but the frontend is still working normally, so it was not noticed before.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template