react + ts 中 // 编辑器配置 const editorConfig: Partial<IEditorConfig> = { // 在编辑器中,点击选中“附件”节点时,要弹出的菜单 hoverbarKeys: { attachment: { menuKeys: ['downloadAttachment'], // “下载附件”菜单 }, }, MENU_CONF: { // 自定义上传图片 uploadImage: { async customUpload(file: File, insertFn: any) { try { const formData = new FormData(); formData.append('file', file); fetchApi(uploadImgFile, { param: formData, onRequestSuccessfull: (ret: any) => { const url = fileSever + ret?.result?.name; const alt = ret?.result?.originalName; const href = fileSever + ret?.result?.name; insertFn(url, alt || '', href || ''); }, }); } catch (error) { console.log(error); } }, }, // 自定义上传视屏 uploadVideo: { async customUpload(file: File, insertFn: any) { try { const formData = new FormData(); formData.append('file', file); fetchApi(uploadImgFile, { param: formData, onRequestSuccessfull: (ret: any) => { const url = fileSever + ret?.result?.name; const alt = ret?.result?.originalName; const href = fileSever + ret?.result?.name; insertFn(url, alt || '', href || ''); }, }); } catch (error) { console.log(error); } }, }, uploadAttachment: { // 自定义上传附件 async customUpload(file: File, insertFn: any) { try { const formData = new FormData(); formData.append('file', file); fetchApi(uploadImgFile, { param: formData, onRequestSuccessfull: (ret: any) => { const url = fileSever + ret?.result?.name; const name = ret?.result?.originalName; insertFn(url, name); }, }); } catch (error) { console.log(error); } }, }, }, };配置了自定义上传附件,但是在上传附件时没有执行自定义上传附件的服务,控制台报错‘Uncaught (in promise) Error: Cannot get upload server address 没有配置上传地址’
时间: 2024-04-27 17:21:16 浏览: 118
【React+TS+UmiJS】react-monaco-editor代码编辑器使用
根据你提供的信息,错误信息显示没有配置上传地址。你需要检查一下 fetchApi 函数调用的 uploadImgFile 参数是否配置正确。此外,你也可以检查一下后端服务是否可以正常访问。如果这些都没有问题,你可以尝试在自定义上传附件的回调函数 onRequestSuccessfull 中打印一下 ret 参数,看看是否正确返回了上传附件的信息。
阅读全文