0

I need to save customized CSS files into AWS S3 using paperclip, and load them back in html file using paperclip attachment url. So, the link tag will looks something like:

 <link rel = "stylesheet" href = "https://s3.us-east-2.amazonaws.com/....../theme.css20190126-23995-3w63v8.css?1548515496"> 

Loading the file in Firefox will show the following error in console:

The stylesheet https://s3.us-east-2.amazonaws.com/....../theme.css20190126-23995-3w63v8.css?1548515496 was not loaded because its MIME type, “text/plain”, is not “text/css”.

I tried using this solution and added .url(:default, timestamp: false) to attachment url. However this give a wrong file url for browser and CSS file is not loaded.

youssef
  • 613
  • 4
  • 16

1 Answers1

0

AWS S3 returns default content-type "text/plain", so you should set Metadata on AWS S3.

  1. Log in your AWS console.
  2. Go to your file (xxx/xxx/theme.css20190126-23995-3w63v8.css) on AWS S3 console.
  3. Open Properties tab of your file.
  4. Add content-type click "+ Add Metadata" on Metadata section.

Of course, you can modify Metadata from programs.

https://docs.aws.amazon.com/en_us/sdk-for-ruby/v3/developer-guide/s3-example-upload-bucket-item-with-metadata.html

mogbee
  • 208
  • 2
  • 5