0

I am creating react and laraval project and I want to use 3d models (.glb type image). I upload .glb type image and after that, I want to display it in my dashboard. I do it using map function as shown in below.

ViewProducts.js

viewProductTable = productlist.map((item) =>{
            return (
                <tr key={item.id}>
                    <td>{item.id}</td>
                    <td>{item.category.name}</td>
                    <td>{item.name}</td>
                    <td>{item.selling_price}</td>
                    <td><model-viewer src={`http://localhost:8000/${item.pimage}`} width="60px" auto-rotate camera-controls></model-viewer></td>
                    <td><Link to={`products/${item.id}`} className="btn btn-success btn-sm">Edit</Link></td>
                    <td><button type="button" onClick={(e) => deleteProduct(e, item.id)} className="btn btn-danger btn-sm">Delete</button></td>
                </tr>
            )
        });

Error:

Access to XMLHttpRequest at 'http://localhost:8000/uploads/products/1640341595.glb' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How fix this error?

Nirodha Lakmali
  • 105
  • 1
  • 1
  • 10
  • add sample in https://codesandbox.io/ – A.R.SEIF Dec 25 '21 at 08:11
  • Check the answer by Nicholas here https://stackoverflow.com/questions/57009371/access-to-xmlhttprequest-at-from-origin-localhost3000-has-been-blocked That should enable your `:8000` project to allow requests from `:3000` project. – Siddharth Bhansali Dec 25 '21 at 13:19
  • @SiddharthBhansali I checked that post but I could not understand what is the solution? Can you explain it? – Nirodha Lakmali Dec 25 '21 at 17:10
  • You are trying to access a file from a project in a different project. So you need to configure the other project to allow requests from the first. For that you need to change some CORS settings. In the answer by Nicholas in the link, he tells you how to do it. – Siddharth Bhansali Dec 26 '21 at 07:44

0 Answers0