Im using action text with trix for my rich text content and Im able to upload images on my trix editor which is then uploaded to my amazon s3 bucket successfully. I'd liek to be able to delete that object in s3 when a user decides to delete the image on the editor. I'm using the AWS sdk for js and I've set my parameters:
window.addEventListener("trix-attachment-remove", function(event) {
var AWS = require('aws-sdk');
AWS.config.credentials = {
accessKeyId: gon.accessKey,
secretAccessKey: gon.secretKey,
region: 'us-west-1'
}
console.log(event.attachment.getAttributes())
var s3 = new AWS.S3();
var params = { Bucket: gon.bucketName, Key: '#object-name#' };
s3.deleteObject(params, function(err, data) {
if (err) console.log(err, err.stack); // error
else console.log(); // deleted
});
})
So my only issue now is getting the key for the object which I understand is the object name. So here's a sample of my objects in s3 bucket with their names:
And Im trying to get the attributes from the file which Im removing. From this code
event.attachment.getAttributes()
And heres what Im getting:
There's no way the sgid or the string at the end of the url matches any of the object name. Its simply too long. How do I get the object name in s3 when Im removign the object?
Also, just an additional note, if I replace the key with the object name directly from s3 bucket, the delete succeeds so I know its working but I just need to get hte correct object name.