[英]unable to upload image to amazon s3 from froala WSIWYG editor
我使用froala編輯器,還具有圖片上傳到S3,我跟着步驟在文檔中提到的在這里
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。 我不知道我可能在哪里出錯,我已經研究過並且沒有找到合適的解決方案。 任何幫助是極大的贊賞。
我找到了上面發布的問題的解決方案,發布了一個答案,因為它可能對遇到這個問題的人有所幫助。
我通過在編輯器的初始化中添加選項imageUploadUrl : false
修復上傳問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.