我正在使用froala编辑器,该编辑器还将图像上传到s3,我按照文档here
中所述的步骤进行操作s3存储桶上的CORS配置
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
服务器端代码
router.route('/get_signature')
.get((req, res) => {
var configs = {
// The name of your bucket.
bucket: process.env.AWS_BUCKET_NAME,
// S3 region. If you are using the default us-east-1, it this can be ignored.
region: 'us-east-1',
// The folder where to upload the images.
keyStart: process.env.AWS_BUCKET_PROJECT_NAME + '/' + process.env.AWS_BUCKET_BLOGS,
// File access.
acl: 'public-read',
// AWS keys.
accessKey: process.env.AWS_ACCESS_KEY_ID,
secretKey: process.env.AWS_SECRET_ACCESS_KEY
}
var s3Hash = FroalaEditor.S3.getHash(configs);
console.log(JSON.stringify(s3Hash) + " :s3Hash");//this holds the s3Hash
res.send(s3Hash);
})
在我的客户端获取请求
$.get('/blog/get_signature', {})
.done(function (s3Hash) {
console.log(JSON.stringify(s3Hash) + " :s3Hash"); //hold the response
$('textarea#froala-editor').froalaEditor({
imageUploadToS3: s3Hash,
paragraphFormat: {
h3: "Blog Title",
h4: "Abstract",
body: "Body"
},
})
.on('froalaEditor.contentChanged', function (e, editor) {
$('#preview').html(editor.html.get());
})
.on('froalaEditor.image.uploadedToS3', function (e, editor, link, key, response) {
// Image was uploaded to the server.
console.log("Image uploaded to s3 " + JSON.stringify(response));
})
})
我试图按照文档进行完善,但是图像仍未上传到s3。我不知道哪里可能出问题,我已经进行了研究和研究,但没有找到适当的解决方案。任何帮助将不胜感激。
答案 0 :(得分:0)
我已经找到了我上面发布的问题的解决方案,并发布了答案,因为这对偶然发现此问题的人可能会有帮助。
我通过在编辑器的初始化内添加选项imageUploadUrl : false
来解决了上传问题。