Search code examples
ruby-on-railsamazon-s3rails-activestorage

Rails Active Storage, delete file from S3 bucket


I am using Active Storage to upload images to S3 bucket. Everything is working fine but when I am deleting image file from console then file is not deleted from S3 bucket. Rails documentation says that using purge will delete file from S3 bucket as well. But in my case I can still see the file in S3 bucket. Below are the commands which I am using to delete file from console.

company = Company.first
company.logo.purge # this is deleting the file in console but not deleting file in S3 bucket.

when I check the log from rails server then its saying deleting from Disk Storage rather than S3. Below is my log.

Disk Storage (0.4ms) Deleted file from key: 1x29cv8bkur97n3fosu9qwfx8316
Disk Storage (0.1ms) Deleted files by key prefix: variants/1x29cv8bkur97n3fosu9qwfx8316/

So how can I delete the file from S3 bucket using rails console.

UPDATE: I don't know what was the problem but restarting my rails console fix the problem.


Solution

  • I don't know what was the problem but restarting my rails console fix the problem.