Rails 6 Active Text + Trix + Active Storage : Delete file from S3

663 Views Asked by At

I can successfully upload image to Amazon S3 using direct Upload but if I remove the image from the Trix rich text it doesn't being deleted from S3 server. I suppose I should do something similar as trix-attachment-remove.

Why this is not default in Rails 6?

enter image description here

application.js

 //= require 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}`,
            });
        }
        });
    }
});
0

There are 0 best solutions below