1

New to remote assets, and can't seem to find any information on accessing remote assets via filepath in areas twig can't be used, such as CSS. I'd like to be able to use those same assets in CSS files but can't seem to find them.

For example, if I named my remote Amazon S3 Asset Source handle to 'amazon', and it has sub folders asset/images/template for an example, would there be a way to reach the files in a file path such as amazon/assets/images/template/filename.jpg for use in CSS and whatnot?

Any information would be greatly appreciated. Thanks!

1 Answer 1

5

This question is really more about S3 than about Craft. What you need for the assets is not the file path, but the url. And yes, S3 assets do have a url. This page describes the format for the host:

<bucket-name>.s3-website-<AWS-region>.amazonaws.com

They give these examples:

This URL requests the photo.jpg object, which is stored at the root level in the bucket.

http://examplebucket.s3-website-us-east-1.amazonaws.com/photo.jpg

This URL requests the docs/doc1.html object in your bucket.

http://examplebucket.s3-website-us-east-1.amazonaws.com/docs/doc1.html
2
  • I feel silly having asked now. Thank you for clarifying that!
    – taylor
    Commented Dec 23, 2015 at 18:28
  • 1
    I'd recommend setting setting up a CNAME in your DNS to point to S3 instead of grabbing it directly (basically mapping your bucket to something like cdn.whatever.com). That gives you some flexibility if you ever need to cut AWS out of the picture or change datacenters within AWS. Commented Dec 28, 2015 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.