我正在使用Angular6,当我使用Froala上传图像时,我在Froala编辑器中收到此错误:
出了点问题。请重试。
我的服务器端代码正常,上传图片,并获得带有正确网址的JSON响应。
我的代码:
//component.ts:
public options: Object = {
charCounterCount: true,
// Set the image upload URL.
imageUploadURL: 'http://localhost:3000/upload_image',
// Additional upload params.
imageUploadParams: {id: 'my_editor'},
// Set request type.
imageUploadMethod: 'POST',
};
//component.html
<div class="row">
<div [froalaEditor]="options" [(froalaModel)]="contenidoTema"></div>
</div>
//server-side code
//app.js
var FroalaEditor = require('wysiwyg-editor-node-sdk/lib/froalaEditor.js');
app.use(express.static(__dirname + '/'));
app.use('/bower_components', express.static(path.join(__dirname, '../bower_components')));
app.use(bodyParser.urlencoded({ extended: false }));
// Path to upload image.
app.post('/upload_image', function (req, res) {
// Store image.
FroalaEditor.Image.upload(req, '/uploads/', function(err, data) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Allow', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
res.setHeader('Content-Length', '0');
// Return data.
if (err) {
return res.send(JSON.stringify(err));
}
console.log("http://localhost:3000"+data.link);
res.send("http://localhost:3000"+data.link);
});
});