D
D
denstuk2020-05-31 23:44:03
PostgreSQL
denstuk, 2020-05-31 23:44:03

How to send photos (Express, PostgreSQL) to the client side (React), where and how to store them?

Hello, this is the situation. I need to send a JSON file with a product description (title, description, price) from the server, which, in turn, I get from the database (PostgreSQL). But along with the description, you need to send a photo of the product. At the moment, the photos are in a separate folder on the server side (Node, Express). I would like to know how to correctly send photos to the client (React)?

DB query:

const getAllProducts = async () => {
    const data = await pool.query('select * from products');
    return data.rows;
};

Sending JSON:
router.get('/api/products', async (req, res) => {
    await db.getAllProducts().then((data) => {
        res.status(200).send(data);
    });
});

I receive data on the client:
componentWillMount() {
        axios('/api/products').then((data) => {
            this.setState(() => ({
                products: data.data
            }))
        });
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
origami1024, 2020-06-01
@origami1024

Don't be smart, send links to pictures

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question