Cloud Clip Clip Configuration

I am trying to configure paperclip with a cloud based interface and my urls are not returning with the correct path or domain.

This is my paperclip configuration:

s3_cr

edentials: { access_key_id: ENV.fetch("S3_ACCESS_KEY"), secret_access_key: ENV.fetch("S3_SECRET"), bucket: ENV.fetch("S3_BUCKET"), }, storage: :s3, url: ':s3_alias_url', s3_host_alias: "xxxx.cloudfront.com", s3_headers: { "Cache-Control" => "max-age=31557600" }, s3_protocol: "https", path: ":rails_root/public/spree/products/:id/:style/:basename.:extension", default_url: "/spree/products/:id/:style/:basename.:extension", default_style: "product", 

All my urls are returned using the default url ... is this correct?

In the model itself, I have some configurations that I worry about overriding :s3_alias_url . Is it possible?

 class Image < Asset validate :no_attachment_errors has_attached_file :attachment, styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>' }, default_style: :product, url: '/spree/products/:id/:style/:basename.:extension', path: ':rails_root/public/spree/products/:id/:style/:basename.:extension' 

What is this actually doing?

My main questions are what happens when we save the image of the model? Are URLs defined then? Or are they determined when we try to find affection? I assume that when we bind an attachment to an image, does it load in s3? But when we try to extract the attachment, we first try to get into the cloud cdn? What's happening?

0
ruby-on-rails cdn
source share
1 answer

There are several issues that I see that are not related to the cloud. I myself did not use cloudfront, but I served S3 objects using CName, and the concept seems to be similar.

In your configuration file you have

 url: ':s3_alias_url', s3_host_alias: "xxxx.cloudfront.com", 

Which is correct in terms of the paperclip installed for use with AWS. What happens here is that your url is looking for your s3_host_alias as a place to start your path when you display images.

However, when you boot, you go to the bucket (in your credentials) and put the object in the path (like bucket_name \ path \ to \ file.jpg).

All my urls are returned using the default url ... is this correct?

Yes. Like.

This is not what you want to do, but it is what you do. In your image model, you set your url: to /spree/products/:id/:style/:basename.:extension and this is also exactly what you have in your default_url: in the configuration file.

So it's hard to see why you get the answer. In most cases, you want default_url: be displayed as an image if there is no image. Looks like page 404, but for images. This should be located on a static path, which, as you know, you can hit even if s3 goes down (which only ever happened once, in my experience).

If you change this, I can add additional information to solve your specific problem, just let me know if you are still clicking on the default path or URL.

(Note. This image appears only if you do not have an attachment. It will not / should not be displayed when attaching the image, but it does not exist where you are looking. For example, if you delete an image from s3 that was found on the checked path.)

I'm worried maybe overrides: s3_alias_url. Is it possible?

Yes. This is what happens with your url in the model, it tells it to check the same path as the default path.

Also I would remove :rails_root from your path. This will help, mainly because rails_root is trying to navigate to a location on your computer and tell your s3 path to build a path to that location. This can become messy (for example, the s3 key may appear and look like / C: / MyDocuments / Sites / MySite / public / spree / products // original / .... It gets rude.)

What is this actually doing?

I don’t understand what part this refers to, but I’ll be happy to answer if you tell me what this means.

My main questions is what happens when we save the image in the model?

When you save the image, you set the key for the s3 object and load the image into your s3 bucket. this key consists of your bucket and path, and it should be noted that the URL is specifically used to retrieve your images. Changes to the URL after the file has been uploaded will change when the paper clip searches for your image.

Are URLs defined then? Or are they determined when we try to extract an attachment?

Url are created when the image is loaded, however, when you link to the image, you should be able to say something like img_tag src="image.attachment" , and it should create a URL to view. (This is difficult to explain without knowing what you have in your mind).

I assume that when we attach the attachment to an image, does it load on s3? yes But when we try to find affection, we first try cloud cdn? What's happening?

When loading, your bucket is used: found in the credentials, when loading (or displaying) it uses the URL built from url: and path:

0
source share

All Articles