Reactjs 当tinymce与react应用程序集成时,CORS给出了错误

Reactjs 当tinymce与react应用程序集成时,CORS给出了错误,reactjs,Reactjs,我已将tinymce与React应用程序集成。一切正常,但当我上传图像时,CORS出现以下错误: plugin.min.js:9在'file:///C:/Users/Javeria/Documents/react/moonleaks/backend/media/images/“来自源”已被CORS策略阻止:跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https export default class App extends Component { handleEd

我已将tinymce与React应用程序集成。一切正常,但当我上传图像时,CORS出现以下错误:

plugin.min.js:9在'file:///C:/Users/Javeria/Documents/react/moonleaks/backend/media/images/“来自源”已被CORS策略阻止:跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https

export default class App extends Component {

handleEditorChange = (e) => {
console.log('Content was updated:', e.target.getContent());
}



render() {
return (
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{
plugins: 'link image code',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | 
code',

selector: 'textarea',  // change this value according to your html


images_upload_url:
'file:///C:/Users/Javeria/Documents/react/moonleaks/backend/media/images/',
images_upload_credentials: true
}}
onChange={this.handleEditorChange}
/>

);
}

Node server function:
var storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'media/images')
},
filename: (req, file, cb) => {
cb(null, file.originalname)
}
});
const upload = multer({ storage })

app.post('/upload', upload.single('image'), (req, res) => {
    if (req.file)
    res.json({
    imageUrl: `images/${req.file.filename}`
    , file_size : req.file});
    else 
    res.status("409").json("No Files to Upload.");
    });                             
导出默认类应用程序扩展组件{
handleEditorChange=(e)=>{
log('内容已更新:',e.target.getContent());
}
render(){
返回(
);
}
节点服务器功能:
var storage=multer.diskStorage({
目的地:(请求、文件、cb)=>{
cb(空,“媒体/图像”)
},
文件名:(请求、文件、cb)=>{
cb(null,file.originalname)
}
});
const upload=multer({storage})
app.post('/upload',upload.single('image'),(req,res)=>{
if(请求文件)
res.json({
imageUrl:`images/${req.file.filename}`
,文件大小:req.file});
其他的
res.status(“409”).json(“没有要上传的文件”);
});                             

如何更正此错误?

您不能直接将图像上载到系统的驱动器文件夹,您必须安装一个服务器来接收图像

images\u upload\u url
替换为服务器上的路径(可以在本地主机上运行)


参考PHP文件上载处理程序

来自哪个库?导入{Editor}来自“@tinymce/tinymce react”;是的,我有一个在url上运行的节点服务器:。我还有一个图像上传功能,工作正常。你可以看看这个功能,因为我在上面的帖子中编辑了代码。但是如何在tinymce中使用此函数?然后尝试将
images\u upload\u url
更改为
localhost:4000/{path\u of\u upload\u function}
我尝试使用此路径:。现在它给出了500(内部服务器错误).I以这种方式在其他地方使用此函数:const uploaders=this.state.images.map(image=>{const data=new FormData();data.append(“image”,image,image.name);axios.post(BASE_URL+'upload',data)})这里的BASE_URL是“”;这意味着服务器端代码中有一些错误,请尝试用不同的问题询问它,并详细解释错误。