I am using React Filepond and the uploading part is working fine. But when I go to an existing record and try to display the image, I get a CORS error:
Access to XMLHttpRequest at 'http://localhost:8000/img/myImg.jpg' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
in app.js on my node server I have the below but I still get the cors error using the cors package
const cors = require("cors");
app.use(cors());
app.options("*", cors());
In React I have the following:
state = {
data: {
title: "",
bgImg: ""
},
errors: {},
files: [
{
source: "myImg.jpg",
options: {
type: "local"
}
}
]
};
<FilePond
ref={ref => (this.pond = ref)}
files={this.state.files}
allowMultiple={false}
maxFiles={1}
name="bgImg"
server={{
process: "http://localhost:8000/api/uploads/",
load: "http://localhost:8000/img/"
}}
oninit={() => this.handleInit()}
onupdatefiles={fileItems => {
this.setState({
files: fileItems.map(fileItem => fileItem.file)
});
}}
/>
In package.json I have also added a proxy:
"proxy": "http://localhost:8000/img",
Network tab -> headers tab shows
Request URL: http://localhost:8000/img/myImg.jpg
Referrer Policy: no-referrer-when-downgrade
Provisional headers are shown
Referer: http://localhost:3000/home-banner