Ruby on rails Rails 5.2:Trix,带主动存储和AWS S3
我正试图通过我的trix编辑器上传图像,并希望将图像上传到AWS S3 图像已成功上载到ActiveStorage,但未上载到S3 然而,我在rails控制台Ruby on rails Rails 5.2:Trix,带主动存储和AWS S3,ruby-on-rails,amazon-s3,trix,Ruby On Rails,Amazon S3,Trix,我正试图通过我的trix编辑器上传图像,并希望将图像上传到AWS S3 图像已成功上载到ActiveStorage,但未上载到S3 然而,我在rails控制台为文件生成的URL中看到了类似的内容,其键为:Gsgdc7Jp84wYTQ1W4s(https://bucket.s3.amazonaws.com/Gsgdc7Jp84wYT2Ya3gxQ1W4s?X-Amz算法=AWS4redential=AKIAX6%2F20200414%2Fus-east-1%2Fs3%2Faws4_请求&X-Amz
为文件生成的URL中看到了类似的内容,其键为:Gsgdc7Jp84wYTQ1W4s(https://bucket.s3.amazonaws.com/Gsgdc7Jp84wYT2Ya3gxQ1W4s?X-Amz算法=AWS4redential=AKIAX6%2F20200414%2Fus-east-1%2Fs3%2Faws4_请求&X-Amz-Date=20241821Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-md5%3B内容类型%3Bhost&X-Amz-Signature=3613D41915E47BAA7A7C90421EEE3F0FFC)
我看到trix文档提供了attachments.js
,可以上传到云提供商https://trix-editor.org/js/attachments.js
下面是我的代码的相关部分,用于上传到ActiveStorage
document.addEventListener('trix-attachment-add', function (event) {
var file = event.attachment.file;
if (file) {
var upload = new window.ActiveStorage.DirectUpload(file,'/rails/active_storage/direct_uploads', window);
upload.create((error, attributes) => {
if (error) {
return false;
} else {
return event.attachment.setAttributes({
url: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
href: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
});
}
});
}
});
以下是我的问题:
1) 如果我的活动存储配置为上传到S3,我还需要attachments.js吗
2) 我的活动存储配置为上传到S3,我在rails控制台中看到了上述响应,但在S3中没有看到文件
如果能帮上忙,那就太好了。谢谢 嗨,你解决这个问题了吗?如果是的话,你能分享你的解决方案吗?嗨@thiebo,我最终使用了attachment.js。你看到了什么错误?谢谢你的回答。在离开弗罗拉之前,我仍在研究trix的各个方面。所以(目前)没有问题。