4

I am trying to have images uploaded via my trix editor and also want to upload the images to AWS S3.

The images are getting succesfully uploaded to ActiveStorage but they are not getting uploaded to S3.

I however see something like this in the rails console Generated URL for file at key: Gsgdc7Jp84wYTQ1W4s (https://bucket.s3.amazonaws.com/Gsgdc7Jp84wYT2Ya3gxQ1W4s?X-Amz-Algorithm=AWS4redential=AKIAX6%2F20200414%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241821Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-md5%3Bcontent-type%3Bhost&X-Amz-Signature=3613d41915e47baaa7c90421eee3f0ffc)

I see that trix documentation provides attachments.js, which uploads to cloud provider https://trix-editor.org/js/attachments.js.

Also below is my relevant part of my code which is used to upload to 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}`,
        });
      }
    });
  }
});

Below are my questions:

1) If my active storage is configured to upload to S3, do i still need attachments.js

2) My active storage is configured to upload to S3 and i see the above response in rails console but do not see the file in S3.

Any help in fixing this would be really great. Thanks.

opensource-developer
  • 2,826
  • 4
  • 38
  • 88

0 Answers0