Express server responds with 404 when requesting blob files

Viewed 248

When I try to get some blob files from the server in my express app, the images don't load, but it loads on other pages of my app.

For example, when I'm in a view that shows all the products in the db, the images show, but when I go into a view of a single product, the server responds with 404 on the blob file.

Do you guys think anything specifically is causing this?

I am using axios to fetch the data from my server.

I checked the type on the network tab and when the image actually loads, it loads the type octet-stream but, when it doesn't, it loads the type text/html, I don't know what went wrong with this but please can anyone instruct me on an error they think I made?

// get a product by id (express endpoint)
// @@@ - public
router.get('/find/:productId', async (req, res) => {
  try {
    const product = await Product.findById(req.params.productId);

    if (!product) {
      return res.status(404).json({ errors: [{ msg: 'Product not found' }] });
    }

    res.json(product);
  } catch (err) {
    console.error(err.message);
    res.status(500).send('Server Error');
  }
});


// fetching the api from redux thunk
export const getItemById = (productId) => async (dispatch) => {
  dispatch(clearItem());
  dispatch(loading());

  try {
    const res = await axios.get(`/api/products/find/${productId}`);

    dispatch({ type: GET_ITEM_BY_ID, payload: res.data });
  } catch (err) {
    dispatch({ type: ITEM_ERROR, payload: 'Error occured' });
  }
};

When I try to display an item which has a field of project images, the images do not show up on the browser and I get the error of 404.

0 Answers
Related